Mercurial > hg > graal-jvmci-8
annotate src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp @ 22294:d86b226e331a
Enable derived oop processing by the GC with JVMCI
author | Tom Rodriguez <tom.rodriguez@oracle.com> |
---|---|
date | Tue, 21 Jul 2015 15:00:07 -0700 |
parents | 7848fc12602b |
children | c28cb37b2e1d |
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 = |
20756 | 741 ((DefNewGeneration*)_young_gen)->max_survivor_size() / plab_sample_minimum_size(); |
1289
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 | |
20756 | 799 size_t CMSCollector::plab_sample_minimum_size() { |
800 // The default value of MinTLABSize is 2k, but there is | |
801 // no way to get the default value if the flag has been overridden. | |
802 return MAX2(ThreadLocalAllocBuffer::min_size() * HeapWordSize, 2 * K); | |
803 } | |
804 | |
0 | 805 const char* ConcurrentMarkSweepGeneration::name() const { |
806 return "concurrent mark-sweep generation"; | |
807 } | |
808 void ConcurrentMarkSweepGeneration::update_counters() { | |
809 if (UsePerfData) { | |
810 _space_counters->update_all(); | |
811 _gen_counters->update_all(); | |
812 } | |
813 } | |
814 | |
815 // this is an optimized version of update_counters(). it takes the | |
816 // used value as a parameter rather than computing it. | |
817 // | |
818 void ConcurrentMarkSweepGeneration::update_counters(size_t used) { | |
819 if (UsePerfData) { | |
820 _space_counters->update_used(used); | |
821 _space_counters->update_capacity(); | |
822 _gen_counters->update_all(); | |
823 } | |
824 } | |
825 | |
826 void ConcurrentMarkSweepGeneration::print() const { | |
827 Generation::print(); | |
828 cmsSpace()->print(); | |
829 } | |
830 | |
831 #ifndef PRODUCT | |
832 void ConcurrentMarkSweepGeneration::print_statistics() { | |
833 cmsSpace()->printFLCensus(0); | |
834 } | |
835 #endif | |
836 | |
837 void ConcurrentMarkSweepGeneration::printOccupancy(const char *s) { | |
838 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
839 if (PrintGCDetails) { | |
840 if (Verbose) { | |
7455
0b54ffe4c2d3
8005672: Clean up some changes to GC logging with GCCause's
jmasa
parents:
6885
diff
changeset
|
841 gclog_or_tty->print("[%d %s-%s: "SIZE_FORMAT"("SIZE_FORMAT")]", |
0 | 842 level(), short_name(), s, used(), capacity()); |
843 } else { | |
7455
0b54ffe4c2d3
8005672: Clean up some changes to GC logging with GCCause's
jmasa
parents:
6885
diff
changeset
|
844 gclog_or_tty->print("[%d %s-%s: "SIZE_FORMAT"K("SIZE_FORMAT"K)]", |
0 | 845 level(), short_name(), s, used() / K, capacity() / K); |
846 } | |
847 } | |
848 if (Verbose) { | |
849 gclog_or_tty->print(" "SIZE_FORMAT"("SIZE_FORMAT")", | |
850 gch->used(), gch->capacity()); | |
851 } else { | |
852 gclog_or_tty->print(" "SIZE_FORMAT"K("SIZE_FORMAT"K)", | |
853 gch->used() / K, gch->capacity() / K); | |
854 } | |
855 } | |
856 | |
857 size_t | |
858 ConcurrentMarkSweepGeneration::contiguous_available() const { | |
859 // dld proposes an improvement in precision here. If the committed | |
860 // part of the space ends in a free block we should add that to | |
861 // uncommitted size in the calculation below. Will make this | |
862 // change later, staying with the approximation below for the | |
863 // time being. -- ysr. | |
864 return MAX2(_virtual_space.uncommitted_size(), unsafe_max_alloc_nogc()); | |
865 } | |
866 | |
867 size_t | |
868 ConcurrentMarkSweepGeneration::unsafe_max_alloc_nogc() const { | |
869 return _cmsSpace->max_alloc_in_words() * HeapWordSize; | |
870 } | |
871 | |
872 size_t ConcurrentMarkSweepGeneration::max_available() const { | |
873 return free() + _virtual_space.uncommitted_size(); | |
874 } | |
875 | |
1888
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
876 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
|
877 size_t available = max_available(); |
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
878 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
|
879 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
|
880 if (Verbose && PrintGCDetails) { |
1888
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
881 gclog_or_tty->print_cr( |
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
882 "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
|
883 "max_promo("SIZE_FORMAT")", |
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
884 res? "":" not", available, res? ">=":"<", |
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
885 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
|
886 } |
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
887 return res; |
0 | 888 } |
889 | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
890 // At a promotion failure dump information on block layout in heap |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
891 // (cms old generation). |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
892 void ConcurrentMarkSweepGeneration::promotion_failure_occurred() { |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
893 if (CMSDumpAtPromotionFailure) { |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
894 cmsSpace()->dump_at_safepoint_with_locks(collector(), gclog_or_tty); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
895 } |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
896 } |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
897 |
0 | 898 CompactibleSpace* |
899 ConcurrentMarkSweepGeneration::first_compaction_space() const { | |
900 return _cmsSpace; | |
901 } | |
902 | |
903 void ConcurrentMarkSweepGeneration::reset_after_compaction() { | |
904 // Clear the promotion information. These pointers can be adjusted | |
905 // along with all the other pointers into the heap but | |
906 // compaction is expected to be a rare event with | |
907 // 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
|
908 if (CollectedHeap::use_parallel_gc_threads()) { |
0 | 909 for (uint i = 0; i < ParallelGCThreads; i++) { |
910 _par_gc_thread_states[i]->promo.reset(); | |
911 } | |
912 } | |
913 } | |
914 | |
915 void ConcurrentMarkSweepGeneration::space_iterate(SpaceClosure* blk, bool usedOnly) { | |
916 blk->do_space(_cmsSpace); | |
917 } | |
918 | |
919 void ConcurrentMarkSweepGeneration::compute_new_size() { | |
920 assert_locked_or_safepoint(Heap_lock); | |
921 | |
922 // If incremental collection failed, we just want to expand | |
923 // to the limit. | |
924 if (incremental_collection_failed()) { | |
925 clear_incremental_collection_failed(); | |
926 grow_to_reserved(); | |
927 return; | |
928 } | |
929 | |
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
|
930 // 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
|
931 // 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
|
932 |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
933 CardGeneration::compute_new_size(); |
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 // 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
|
936 if (did_compact()) { |
06ab37f08701
8013184: CMS: Call reset_after_compaction() only if a compaction has been done
jmasa
parents:
10243
diff
changeset
|
937 cmsSpace()->reset_after_compaction(); |
06ab37f08701
8013184: CMS: Call reset_after_compaction() only if a compaction has been done
jmasa
parents:
10243
diff
changeset
|
938 } |
9072
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
939 } |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
940 |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
941 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
|
942 assert_locked_or_safepoint(Heap_lock); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
943 |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
944 // 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
|
945 // to the limit. |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
946 if (incremental_collection_failed()) { |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
947 clear_incremental_collection_failed(); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
948 grow_to_reserved(); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
949 return; |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
950 } |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
951 |
0 | 952 double free_percentage = ((double) free()) / capacity(); |
953 double desired_free_percentage = (double) MinHeapFreeRatio / 100; | |
954 double maximum_free_percentage = (double) MaxHeapFreeRatio / 100; | |
955 | |
956 // compute expansion delta needed for reaching desired free percentage | |
957 if (free_percentage < desired_free_percentage) { | |
958 size_t desired_capacity = (size_t)(used() / ((double) 1 - desired_free_percentage)); | |
959 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
|
960 size_t expand_bytes = MAX2(desired_capacity - capacity(), MinHeapDeltaBytes); |
0 | 961 if (PrintGCDetails && Verbose) { |
962 size_t desired_capacity = (size_t)(used() / ((double) 1 - desired_free_percentage)); | |
963 gclog_or_tty->print_cr("\nFrom compute_new_size: "); | |
964 gclog_or_tty->print_cr(" Free fraction %f", free_percentage); | |
965 gclog_or_tty->print_cr(" Desired free fraction %f", | |
966 desired_free_percentage); | |
967 gclog_or_tty->print_cr(" Maximum free fraction %f", | |
968 maximum_free_percentage); | |
969 gclog_or_tty->print_cr(" Capactiy "SIZE_FORMAT, capacity()/1000); | |
970 gclog_or_tty->print_cr(" Desired capacity "SIZE_FORMAT, | |
971 desired_capacity/1000); | |
972 int prev_level = level() - 1; | |
973 if (prev_level >= 0) { | |
974 size_t prev_size = 0; | |
975 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
976 Generation* prev_gen = gch->_gens[prev_level]; | |
977 prev_size = prev_gen->capacity(); | |
978 gclog_or_tty->print_cr(" Younger gen size "SIZE_FORMAT, | |
979 prev_size/1000); | |
980 } | |
981 gclog_or_tty->print_cr(" unsafe_max_alloc_nogc "SIZE_FORMAT, | |
982 unsafe_max_alloc_nogc()/1000); | |
983 gclog_or_tty->print_cr(" contiguous available "SIZE_FORMAT, | |
984 contiguous_available()/1000); | |
985 gclog_or_tty->print_cr(" Expand by "SIZE_FORMAT" (bytes)", | |
986 expand_bytes); | |
987 } | |
988 // safe if expansion fails | |
989 expand(expand_bytes, 0, CMSExpansionCause::_satisfy_free_ratio); | |
990 if (PrintGCDetails && Verbose) { | |
991 gclog_or_tty->print_cr(" Expanded free fraction %f", | |
992 ((double) free()) / capacity()); | |
993 } | |
9072
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
994 } else { |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
995 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
|
996 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
|
997 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
|
998 // 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
|
999 if (shrink_bytes >= MinHeapDeltaBytes) { |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
1000 shrink_free_list_by(shrink_bytes); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
1001 } |
0 | 1002 } |
1003 } | |
1004 | |
1005 Mutex* ConcurrentMarkSweepGeneration::freelistLock() const { | |
1006 return cmsSpace()->freelistLock(); | |
1007 } | |
1008 | |
1009 HeapWord* ConcurrentMarkSweepGeneration::allocate(size_t size, | |
1010 bool tlab) { | |
1011 CMSSynchronousYieldRequest yr; | |
1012 MutexLockerEx x(freelistLock(), | |
1013 Mutex::_no_safepoint_check_flag); | |
1014 return have_lock_and_allocate(size, tlab); | |
1015 } | |
1016 | |
1017 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
|
1018 bool tlab /* ignored */) { |
0 | 1019 assert_lock_strong(freelistLock()); |
1020 size_t adjustedSize = CompactibleFreeListSpace::adjustObjectSize(size); | |
1021 HeapWord* res = cmsSpace()->allocate(adjustedSize); | |
1022 // Allocate the object live (grey) if the background collector has | |
1023 // started marking. This is necessary because the marker may | |
1024 // have passed this address and consequently this object will | |
1025 // not otherwise be greyed and would be incorrectly swept up. | |
1026 // Note that if this object contains references, the writing | |
1027 // of those references will dirty the card containing this object | |
1028 // allowing the object to be blackened (and its references scanned) | |
1029 // either during a preclean phase or at the final checkpoint. | |
1030 if (res != NULL) { | |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1031 // 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
|
1032 // 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
|
1033 // 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
|
1034 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
|
1035 assert(!((FreeChunk*)res)->is_free(), "Error, block will look free but show wrong size"); |
0 | 1036 collector()->direct_allocated(res, adjustedSize); |
1037 _direct_allocated_words += adjustedSize; | |
1038 // allocation counters | |
1039 NOT_PRODUCT( | |
1040 _numObjectsAllocated++; | |
1041 _numWordsAllocated += (int)adjustedSize; | |
1042 ) | |
1043 } | |
1044 return res; | |
1045 } | |
1046 | |
1047 // In the case of direct allocation by mutators in a generation that | |
1048 // is being concurrently collected, the object must be allocated | |
1049 // live (grey) if the background collector has started marking. | |
1050 // This is necessary because the marker may | |
1051 // have passed this address and consequently this object will | |
1052 // not otherwise be greyed and would be incorrectly swept up. | |
1053 // Note that if this object contains references, the writing | |
1054 // of those references will dirty the card containing this object | |
1055 // allowing the object to be blackened (and its references scanned) | |
1056 // either during a preclean phase or at the final checkpoint. | |
1057 void CMSCollector::direct_allocated(HeapWord* start, size_t size) { | |
1058 assert(_markBitMap.covers(start, size), "Out of bounds"); | |
1059 if (_collectorState >= Marking) { | |
1060 MutexLockerEx y(_markBitMap.lock(), | |
1061 Mutex::_no_safepoint_check_flag); | |
1062 // [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
|
1063 // |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1064 // Can the P-bits be deleted now? JJJ |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1065 // |
0 | 1066 // 1. need to mark the object as live so it isn't collected |
1067 // 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
|
1068 // 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
|
1069 // 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
|
1070 // 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
|
1071 // 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
|
1072 // as soon as they are initialized.) |
0 | 1073 _markBitMap.mark(start); // object is live |
1074 _markBitMap.mark(start + 1); // object is potentially uninitialized? | |
1075 _markBitMap.mark(start + size - 1); | |
1076 // mark end of object | |
1077 } | |
1078 // check that oop looks uninitialized | |
187 | 1079 assert(oop(start)->klass_or_null() == NULL, "_klass should be NULL"); |
0 | 1080 } |
1081 | |
1082 void CMSCollector::promoted(bool par, HeapWord* start, | |
1083 bool is_obj_array, size_t obj_size) { | |
1084 assert(_markBitMap.covers(start), "Out of bounds"); | |
1085 // See comment in direct_allocated() about when objects should | |
1086 // be allocated live. | |
1087 if (_collectorState >= Marking) { | |
1088 // we already hold the marking bit map lock, taken in | |
1089 // the prologue | |
1090 if (par) { | |
1091 _markBitMap.par_mark(start); | |
1092 } else { | |
1093 _markBitMap.mark(start); | |
1094 } | |
1095 // We don't need to mark the object as uninitialized (as | |
1096 // in direct_allocated above) because this is being done with the | |
1097 // 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
|
1098 // 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
|
1099 // 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
|
1100 // 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
|
1101 // 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
|
1102 // 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
|
1103 // 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
|
1104 // becoming a bona-fide object when the copy/promotion is complete. |
0 | 1105 assert(SafepointSynchronize::is_at_safepoint(), |
1106 "expect promotion only at safepoints"); | |
1107 | |
1108 if (_collectorState < Sweeping) { | |
1109 // Mark the appropriate cards in the modUnionTable, so that | |
1110 // this object gets scanned before the sweep. If this is | |
1111 // not done, CMS generation references in the object might | |
1112 // not get marked. | |
1113 // For the case of arrays, which are otherwise precisely | |
1114 // marked, we need to dirty the entire array, not just its head. | |
1115 if (is_obj_array) { | |
1116 // The [par_]mark_range() method expects mr.end() below to | |
1117 // be aligned to the granularity of a bit's representation | |
1118 // in the heap. In the case of the MUT below, that's a | |
1119 // card size. | |
1120 MemRegion mr(start, | |
1121 (HeapWord*)round_to((intptr_t)(start + obj_size), | |
1122 CardTableModRefBS::card_size /* bytes */)); | |
1123 if (par) { | |
1124 _modUnionTable.par_mark_range(mr); | |
1125 } else { | |
1126 _modUnionTable.mark_range(mr); | |
1127 } | |
1128 } else { // not an obj array; we can just mark the head | |
1129 if (par) { | |
1130 _modUnionTable.par_mark(start); | |
1131 } else { | |
1132 _modUnionTable.mark(start); | |
1133 } | |
1134 } | |
1135 } | |
1136 } | |
1137 } | |
1138 | |
1139 static inline size_t percent_of_space(Space* space, HeapWord* addr) | |
1140 { | |
1141 size_t delta = pointer_delta(addr, space->bottom()); | |
1142 return (size_t)(delta * 100.0 / (space->capacity() / HeapWordSize)); | |
1143 } | |
1144 | |
1145 void CMSCollector::icms_update_allocation_limits() | |
1146 { | |
1147 Generation* gen0 = GenCollectedHeap::heap()->get_gen(0); | |
1148 EdenSpace* eden = gen0->as_DefNewGeneration()->eden(); | |
1149 | |
1150 const unsigned int duty_cycle = stats().icms_update_duty_cycle(); | |
1151 if (CMSTraceIncrementalPacing) { | |
1152 stats().print(); | |
1153 } | |
1154 | |
1155 assert(duty_cycle <= 100, "invalid duty cycle"); | |
1156 if (duty_cycle != 0) { | |
1157 // The duty_cycle is a percentage between 0 and 100; convert to words and | |
1158 // then compute the offset from the endpoints of the space. | |
1159 size_t free_words = eden->free() / HeapWordSize; | |
1160 double free_words_dbl = (double)free_words; | |
1161 size_t duty_cycle_words = (size_t)(free_words_dbl * duty_cycle / 100.0); | |
1162 size_t offset_words = (free_words - duty_cycle_words) / 2; | |
1163 | |
1164 _icms_start_limit = eden->top() + offset_words; | |
1165 _icms_stop_limit = eden->end() - offset_words; | |
1166 | |
1167 // The limits may be adjusted (shifted to the right) by | |
1168 // CMSIncrementalOffset, to allow the application more mutator time after a | |
1169 // young gen gc (when all mutators were stopped) and before CMS starts and | |
1170 // takes away one or more cpus. | |
1171 if (CMSIncrementalOffset != 0) { | |
1172 double adjustment_dbl = free_words_dbl * CMSIncrementalOffset / 100.0; | |
1173 size_t adjustment = (size_t)adjustment_dbl; | |
1174 HeapWord* tmp_stop = _icms_stop_limit + adjustment; | |
1175 if (tmp_stop > _icms_stop_limit && tmp_stop < eden->end()) { | |
1176 _icms_start_limit += adjustment; | |
1177 _icms_stop_limit = tmp_stop; | |
1178 } | |
1179 } | |
1180 } | |
1181 if (duty_cycle == 0 || (_icms_start_limit == _icms_stop_limit)) { | |
1182 _icms_start_limit = _icms_stop_limit = eden->end(); | |
1183 } | |
1184 | |
1185 // Install the new start limit. | |
1186 eden->set_soft_end(_icms_start_limit); | |
1187 | |
1188 if (CMSTraceIncrementalMode) { | |
1189 gclog_or_tty->print(" icms alloc limits: " | |
1190 PTR_FORMAT "," PTR_FORMAT | |
1191 " (" SIZE_FORMAT "%%," SIZE_FORMAT "%%) ", | |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17935
diff
changeset
|
1192 p2i(_icms_start_limit), p2i(_icms_stop_limit), |
0 | 1193 percent_of_space(eden, _icms_start_limit), |
1194 percent_of_space(eden, _icms_stop_limit)); | |
1195 if (Verbose) { | |
1196 gclog_or_tty->print("eden: "); | |
1197 eden->print_on(gclog_or_tty); | |
1198 } | |
1199 } | |
1200 } | |
1201 | |
1202 // Any changes here should try to maintain the invariant | |
1203 // that if this method is called with _icms_start_limit | |
1204 // and _icms_stop_limit both NULL, then it should return NULL | |
1205 // and not notify the icms thread. | |
1206 HeapWord* | |
1207 CMSCollector::allocation_limit_reached(Space* space, HeapWord* top, | |
1208 size_t word_size) | |
1209 { | |
1210 // A start_limit equal to end() means the duty cycle is 0, so treat that as a | |
1211 // nop. | |
1212 if (CMSIncrementalMode && _icms_start_limit != space->end()) { | |
1213 if (top <= _icms_start_limit) { | |
1214 if (CMSTraceIncrementalMode) { | |
1215 space->print_on(gclog_or_tty); | |
1216 gclog_or_tty->stamp(); | |
1217 gclog_or_tty->print_cr(" start limit top=" PTR_FORMAT | |
1218 ", new limit=" PTR_FORMAT | |
1219 " (" SIZE_FORMAT "%%)", | |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17935
diff
changeset
|
1220 p2i(top), p2i(_icms_stop_limit), |
0 | 1221 percent_of_space(space, _icms_stop_limit)); |
1222 } | |
1223 ConcurrentMarkSweepThread::start_icms(); | |
1224 assert(top < _icms_stop_limit, "Tautology"); | |
1225 if (word_size < pointer_delta(_icms_stop_limit, top)) { | |
1226 return _icms_stop_limit; | |
1227 } | |
1228 | |
1229 // The allocation will cross both the _start and _stop limits, so do the | |
1230 // stop notification also and return end(). | |
1231 if (CMSTraceIncrementalMode) { | |
1232 space->print_on(gclog_or_tty); | |
1233 gclog_or_tty->stamp(); | |
1234 gclog_or_tty->print_cr(" +stop limit top=" PTR_FORMAT | |
1235 ", new limit=" PTR_FORMAT | |
1236 " (" SIZE_FORMAT "%%)", | |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17935
diff
changeset
|
1237 p2i(top), p2i(space->end()), |
0 | 1238 percent_of_space(space, space->end())); |
1239 } | |
1240 ConcurrentMarkSweepThread::stop_icms(); | |
1241 return space->end(); | |
1242 } | |
1243 | |
1244 if (top <= _icms_stop_limit) { | |
1245 if (CMSTraceIncrementalMode) { | |
1246 space->print_on(gclog_or_tty); | |
1247 gclog_or_tty->stamp(); | |
1248 gclog_or_tty->print_cr(" stop limit top=" PTR_FORMAT | |
1249 ", new limit=" PTR_FORMAT | |
1250 " (" SIZE_FORMAT "%%)", | |
1251 top, space->end(), | |
1252 percent_of_space(space, space->end())); | |
1253 } | |
1254 ConcurrentMarkSweepThread::stop_icms(); | |
1255 return space->end(); | |
1256 } | |
1257 | |
1258 if (CMSTraceIncrementalMode) { | |
1259 space->print_on(gclog_or_tty); | |
1260 gclog_or_tty->stamp(); | |
1261 gclog_or_tty->print_cr(" end limit top=" PTR_FORMAT | |
1262 ", new limit=" PTR_FORMAT, | |
1263 top, NULL); | |
1264 } | |
1265 } | |
1266 | |
1267 return NULL; | |
1268 } | |
1269 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
1270 oop ConcurrentMarkSweepGeneration::promote(oop obj, size_t obj_size) { |
0 | 1271 assert(obj_size == (size_t)obj->size(), "bad obj_size passed in"); |
1272 // allocate, copy and if necessary update promoinfo -- | |
1273 // delegate to underlying space. | |
1274 assert_lock_strong(freelistLock()); | |
1275 | |
1276 #ifndef PRODUCT | |
1277 if (Universe::heap()->promotion_should_fail()) { | |
1278 return NULL; | |
1279 } | |
1280 #endif // #ifndef PRODUCT | |
1281 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
1282 oop res = _cmsSpace->promote(obj, obj_size); |
0 | 1283 if (res == NULL) { |
1284 // expand and retry | |
1285 size_t s = _cmsSpace->expansionSpaceRequired(obj_size); // HeapWords | |
1286 expand(s*HeapWordSize, MinHeapDeltaBytes, | |
1287 CMSExpansionCause::_satisfy_promotion); | |
1288 // Since there's currently no next generation, we don't try to promote | |
1289 // into a more senior generation. | |
1290 assert(next_gen() == NULL, "assumption, based upon which no attempt " | |
1291 "is made to pass on a possibly failing " | |
1292 "promotion to next generation"); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
1293 res = _cmsSpace->promote(obj, obj_size); |
0 | 1294 } |
1295 if (res != NULL) { | |
1296 // See comment in allocate() about when objects should | |
1297 // be allocated live. | |
1298 assert(obj->is_oop(), "Will dereference klass pointer below"); | |
1299 collector()->promoted(false, // Not parallel | |
1300 (HeapWord*)res, obj->is_objArray(), obj_size); | |
1301 // promotion counters | |
1302 NOT_PRODUCT( | |
1303 _numObjectsPromoted++; | |
1304 _numWordsPromoted += | |
1305 (int)(CompactibleFreeListSpace::adjustObjectSize(obj->size())); | |
1306 ) | |
1307 } | |
1308 return res; | |
1309 } | |
1310 | |
1311 | |
1312 HeapWord* | |
1313 ConcurrentMarkSweepGeneration::allocation_limit_reached(Space* space, | |
1314 HeapWord* top, | |
1315 size_t word_sz) | |
1316 { | |
1317 return collector()->allocation_limit_reached(space, top, word_sz); | |
1318 } | |
1319 | |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1320 // 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
|
1321 // --------------------------------------------------- |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1322 // 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
|
1323 // 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
|
1324 // 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
|
1325 // 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
|
1326 // be accurately determined. |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1327 // 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
|
1328 // ----------------------------------------------------- |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1329 // 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
|
1330 // |
1777
179464550c7d
6983930: CMS: Various small cleanups ca September 2010
ysr
parents:
1720
diff
changeset
|
1331 // 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
|
1332 // obj->size() computes correct size |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1333 // |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1334 // TRANSIENT: klass_word == 0; size is indeterminate until we become an OBJECT |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1335 // |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1336 // STATE IDENTIFICATION: (64 bit+COOPS) |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1337 // ------------------------------------ |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1338 // 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
|
1339 // |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1340 // 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
|
1341 // obj->size() computes correct size |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1342 // |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1343 // 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
|
1344 // |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1345 // |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1346 // STATE TRANSITION DIAGRAM |
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 // mut / parnew mut / parnew |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1349 // FREE --------------------> TRANSIENT ---------------------> OBJECT --| |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1350 // ^ | |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1351 // |------------------------ DEAD <------------------------------------| |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1352 // sweep mut |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1353 // |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1354 // 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
|
1355 // 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
|
1356 // 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
|
1357 // 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
|
1358 // 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
|
1359 |
0 | 1360 // Things to support parallel young-gen collection. |
1361 oop | |
1362 ConcurrentMarkSweepGeneration::par_promote(int thread_num, | |
1363 oop old, markOop m, | |
1364 size_t word_sz) { | |
1365 #ifndef PRODUCT | |
1366 if (Universe::heap()->promotion_should_fail()) { | |
1367 return NULL; | |
1368 } | |
1369 #endif // #ifndef PRODUCT | |
1370 | |
1371 CMSParGCThreadState* ps = _par_gc_thread_states[thread_num]; | |
1372 PromotionInfo* promoInfo = &ps->promo; | |
1373 // if we are tracking promotions, then first ensure space for | |
1374 // promotion (including spooling space for saving header if necessary). | |
1375 // then allocate and copy, then track promoted info if needed. | |
1376 // When tracking (see PromotionInfo::track()), the mark word may | |
1377 // be displaced and in this case restoration of the mark word | |
1378 // occurs in the (oop_since_save_marks_)iterate phase. | |
1379 if (promoInfo->tracking() && !promoInfo->ensure_spooling_space()) { | |
1380 // Out of space for allocating spooling buffers; | |
1381 // try expanding and allocating spooling buffers. | |
1382 if (!expand_and_ensure_spooling_space(promoInfo)) { | |
1383 return NULL; | |
1384 } | |
1385 } | |
1386 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
|
1387 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
|
1388 HeapWord* obj_ptr = ps->lab.alloc(alloc_sz); |
0 | 1389 if (obj_ptr == NULL) { |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1390 obj_ptr = expand_and_par_lab_allocate(ps, alloc_sz); |
0 | 1391 if (obj_ptr == NULL) { |
1392 return NULL; | |
1393 } | |
1394 } | |
1395 oop obj = oop(obj_ptr); | |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1396 OrderAccess::storestore(); |
187 | 1397 assert(obj->klass_or_null() == NULL, "Object should be uninitialized here."); |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
1398 assert(!((FreeChunk*)obj_ptr)->is_free(), "Error, block will look free but show wrong size"); |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1399 // IMPORTANT: See note on object initialization for CMS above. |
0 | 1400 // Otherwise, copy the object. Here we must be careful to insert the |
1401 // klass pointer last, since this marks the block as an allocated object. | |
187 | 1402 // Except with compressed oops it's the mark word. |
0 | 1403 HeapWord* old_ptr = (HeapWord*)old; |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1404 // Restore the mark word copied above. |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1405 obj->set_mark(m); |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1406 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
|
1407 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
|
1408 OrderAccess::storestore(); |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1409 |
12226
7944aba7ba41
8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents:
12112
diff
changeset
|
1410 if (UseCompressedClassPointers) { |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1411 // 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
|
1412 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
|
1413 } |
0 | 1414 if (word_sz > (size_t)oopDesc::header_size()) { |
1415 Copy::aligned_disjoint_words(old_ptr + oopDesc::header_size(), | |
1416 obj_ptr + oopDesc::header_size(), | |
1417 word_sz - oopDesc::header_size()); | |
1418 } | |
187 | 1419 |
0 | 1420 // Now we can track the promoted object, if necessary. We take care |
1521 | 1421 // to delay the transition from uninitialized to full object |
0 | 1422 // (i.e., insertion of klass pointer) until after, so that it |
1423 // atomically becomes a promoted object. | |
1424 if (promoInfo->tracking()) { | |
1425 promoInfo->track((PromotedObject*)obj, old->klass()); | |
1426 } | |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1427 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
|
1428 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
|
1429 assert(old->is_oop(), "Will use and dereference old klass ptr below"); |
187 | 1430 |
1431 // 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
|
1432 OrderAccess::storestore(); |
0 | 1433 obj->set_klass(old->klass()); |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1434 // 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
|
1435 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
|
1436 |
0 | 1437 collector()->promoted(true, // parallel |
1438 obj_ptr, old->is_objArray(), word_sz); | |
1439 | |
1440 NOT_PRODUCT( | |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1441 Atomic::inc_ptr(&_numObjectsPromoted); |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1442 Atomic::add_ptr(alloc_sz, &_numWordsPromoted); |
0 | 1443 ) |
1444 | |
1445 return obj; | |
1446 } | |
1447 | |
1448 void | |
1449 ConcurrentMarkSweepGeneration:: | |
1450 par_promote_alloc_undo(int thread_num, | |
1451 HeapWord* obj, size_t word_sz) { | |
1452 // CMS does not support promotion undo. | |
1453 ShouldNotReachHere(); | |
1454 } | |
1455 | |
1456 void | |
1457 ConcurrentMarkSweepGeneration:: | |
1458 par_promote_alloc_done(int thread_num) { | |
1459 CMSParGCThreadState* ps = _par_gc_thread_states[thread_num]; | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
1460 ps->lab.retire(thread_num); |
0 | 1461 } |
1462 | |
1463 void | |
1464 ConcurrentMarkSweepGeneration:: | |
1465 par_oop_since_save_marks_iterate_done(int thread_num) { | |
1466 CMSParGCThreadState* ps = _par_gc_thread_states[thread_num]; | |
1467 ParScanWithoutBarrierClosure* dummy_cl = NULL; | |
1468 ps->promo.promoted_oops_iterate_nv(dummy_cl); | |
1469 } | |
1470 | |
1471 bool ConcurrentMarkSweepGeneration::should_collect(bool full, | |
1472 size_t size, | |
1473 bool tlab) | |
1474 { | |
1475 // We allow a STW collection only if a full | |
1476 // collection was requested. | |
1477 return full || should_allocate(size, tlab); // FIX ME !!! | |
1478 // This and promotion failure handling are connected at the | |
1479 // hip and should be fixed by untying them. | |
1480 } | |
1481 | |
1482 bool CMSCollector::shouldConcurrentCollect() { | |
1483 if (_full_gc_requested) { | |
1484 if (Verbose && PrintGCDetails) { | |
1485 gclog_or_tty->print_cr("CMSCollector: collect because of explicit " | |
1520
bb843ebc7c55
6919638: CMS: ExplicitGCInvokesConcurrent misinteracts with gc locker
ysr
parents:
1518
diff
changeset
|
1486 " gc request (or gc_locker)"); |
0 | 1487 } |
1488 return true; | |
1489 } | |
1490 | |
1491 // For debugging purposes, change the type of collection. | |
1492 // If the rotation is not on the concurrent collection | |
1493 // type, don't start a concurrent collection. | |
1494 NOT_PRODUCT( | |
1495 if (RotateCMSCollectionTypes && | |
1496 (_cmsGen->debug_collection_type() != | |
1497 ConcurrentMarkSweepGeneration::Concurrent_collection_type)) { | |
1498 assert(_cmsGen->debug_collection_type() != | |
1499 ConcurrentMarkSweepGeneration::Unknown_collection_type, | |
1500 "Bad cms collection type"); | |
1501 return false; | |
1502 } | |
1503 ) | |
1504 | |
1505 FreelistLocker x(this); | |
1506 // ------------------------------------------------------------------ | |
1507 // Print out lots of information which affects the initiation of | |
1508 // a collection. | |
1509 if (PrintCMSInitiationStatistics && stats().valid()) { | |
1510 gclog_or_tty->print("CMSCollector shouldConcurrentCollect: "); | |
1511 gclog_or_tty->stamp(); | |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17935
diff
changeset
|
1512 gclog_or_tty->cr(); |
0 | 1513 stats().print_on(gclog_or_tty); |
1514 gclog_or_tty->print_cr("time_until_cms_gen_full %3.7f", | |
1515 stats().time_until_cms_gen_full()); | |
1516 gclog_or_tty->print_cr("free="SIZE_FORMAT, _cmsGen->free()); | |
1517 gclog_or_tty->print_cr("contiguous_available="SIZE_FORMAT, | |
1518 _cmsGen->contiguous_available()); | |
1519 gclog_or_tty->print_cr("promotion_rate=%g", stats().promotion_rate()); | |
1520 gclog_or_tty->print_cr("cms_allocation_rate=%g", stats().cms_allocation_rate()); | |
1521 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
|
1522 gclog_or_tty->print_cr("initiatingOccupancy=%3.7f", _cmsGen->initiating_occupancy()); |
20326
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1523 gclog_or_tty->print_cr("cms_time_since_begin=%3.7f", stats().cms_time_since_begin()); |
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1524 gclog_or_tty->print_cr("cms_time_since_end=%3.7f", stats().cms_time_since_end()); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1525 gclog_or_tty->print_cr("metadata initialized %d", |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1526 MetaspaceGC::should_concurrent_collect()); |
0 | 1527 } |
1528 // ------------------------------------------------------------------ | |
1529 | |
1530 // If the estimated time to complete a cms collection (cms_duration()) | |
1531 // is less than the estimated time remaining until the cms generation | |
1532 // is full, start a collection. | |
1533 if (!UseCMSInitiatingOccupancyOnly) { | |
1534 if (stats().valid()) { | |
1535 if (stats().time_until_cms_start() == 0.0) { | |
1536 return true; | |
1537 } | |
1538 } else { | |
1539 // We want to conservatively collect somewhat early in order | |
1540 // to try and "bootstrap" our CMS/promotion statistics; | |
1541 // this branch will not fire after the first successful CMS | |
1542 // collection because the stats should then be valid. | |
1543 if (_cmsGen->occupancy() >= _bootstrap_occupancy) { | |
1544 if (Verbose && PrintGCDetails) { | |
1545 gclog_or_tty->print_cr( | |
1546 " CMSCollector: collect for bootstrapping statistics:" | |
1547 " occupancy = %f, boot occupancy = %f", _cmsGen->occupancy(), | |
1548 _bootstrap_occupancy); | |
1549 } | |
1550 return true; | |
1551 } | |
1552 } | |
1553 } | |
1554 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1555 // Otherwise, we start a collection cycle if |
0 | 1556 // old gen want a collection cycle started. Each may use |
1557 // an appropriate criterion for making this decision. | |
1558 // 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
|
1559 // 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
|
1560 if (_cmsGen->should_concurrent_collect()) { |
0 | 1561 if (Verbose && PrintGCDetails) { |
1562 gclog_or_tty->print_cr("CMS old gen initiated"); | |
1563 } | |
1564 return true; | |
1565 } | |
1566 | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1567 // 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
|
1568 // 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
|
1569 // late anyway. |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1570 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1571 assert(gch->collector_policy()->is_two_generation_policy(), |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1572 "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
|
1573 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
|
1574 if (Verbose && PrintGCDetails) { |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1575 gclog_or_tty->print("CMSCollector: collect because incremental collection will fail "); |
0 | 1576 } |
1577 return true; | |
1578 } | |
1579 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1580 if (MetaspaceGC::should_concurrent_collect()) { |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
1581 if (Verbose && PrintGCDetails) { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1582 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
|
1583 } |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
1584 return true; |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
1585 } |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1586 |
20326
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1587 // CMSTriggerInterval starts a CMS cycle if enough time has passed. |
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1588 if (CMSTriggerInterval >= 0) { |
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1589 if (CMSTriggerInterval == 0) { |
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1590 // Trigger always |
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1591 return true; |
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1592 } |
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1593 |
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1594 // Check the CMS time since begin (we do not check the stats validity |
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1595 // as we want to be able to trigger the first CMS cycle as well) |
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1596 if (stats().cms_time_since_begin() >= (CMSTriggerInterval / ((double) MILLIUNITS))) { |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1597 if (Verbose && PrintGCDetails) { |
20326
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1598 if (stats().valid()) { |
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1599 gclog_or_tty->print_cr("CMSCollector: collect because of trigger interval (time since last begin %3.7f secs)", |
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1600 stats().cms_time_since_begin()); |
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1601 } else { |
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1602 gclog_or_tty->print_cr("CMSCollector: collect because of trigger interval (first collection)"); |
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1603 } |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1604 } |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1605 return true; |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1606 } |
20326
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1607 } |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1608 |
0 | 1609 return false; |
1610 } | |
1611 | |
10244
06ab37f08701
8013184: CMS: Call reset_after_compaction() only if a compaction has been done
jmasa
parents:
10243
diff
changeset
|
1612 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
|
1613 |
0 | 1614 // Clear _expansion_cause fields of constituent generations |
1615 void CMSCollector::clear_expansion_cause() { | |
1616 _cmsGen->clear_expansion_cause(); | |
1617 } | |
1618 | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1619 // 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
|
1620 // 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
|
1621 // 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
|
1622 // 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
|
1623 // 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
|
1624 // UseCMSInitiatingOccupancyOnly. This also has the advantage of |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1625 // 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
|
1626 // collections. |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1627 // 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
|
1628 // conditions hold: |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1629 // . our current occupancy exceeds the configured initiating occupancy |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1630 // for this generation, or |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1631 // . 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
|
1632 // expansion, done a collection of this generation, or |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1633 // . 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
|
1634 // 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
|
1635 // 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
|
1636 // 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
|
1637 // the generation, etc... or ... |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1638 // [.(currently done by CMSCollector::shouldConcurrentCollect() only for |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1639 // 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
|
1640 // 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
|
1641 // 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
|
1642 bool ConcurrentMarkSweepGeneration::should_concurrent_collect() const { |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1643 |
0 | 1644 assert_lock_strong(freelistLock()); |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1645 if (occupancy() > initiating_occupancy()) { |
0 | 1646 if (PrintGCDetails && Verbose) { |
1647 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
|
1648 short_name(), occupancy(), initiating_occupancy()); |
0 | 1649 } |
1650 return true; | |
1651 } | |
1652 if (UseCMSInitiatingOccupancyOnly) { | |
1653 return false; | |
1654 } | |
1655 if (expansion_cause() == CMSExpansionCause::_satisfy_allocation) { | |
1656 if (PrintGCDetails && Verbose) { | |
1657 gclog_or_tty->print(" %s: collect because expanded for allocation ", | |
1658 short_name()); | |
1659 } | |
1660 return true; | |
1661 } | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1662 if (_cmsSpace->should_concurrent_collect()) { |
0 | 1663 if (PrintGCDetails && Verbose) { |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1664 gclog_or_tty->print(" %s: collect because cmsSpace says so ", |
0 | 1665 short_name()); |
1666 } | |
1667 return true; | |
1668 } | |
1669 return false; | |
1670 } | |
1671 | |
1672 void ConcurrentMarkSweepGeneration::collect(bool full, | |
1673 bool clear_all_soft_refs, | |
1674 size_t size, | |
1675 bool tlab) | |
1676 { | |
1677 collector()->collect(full, clear_all_soft_refs, size, tlab); | |
1678 } | |
1679 | |
1680 void CMSCollector::collect(bool full, | |
1681 bool clear_all_soft_refs, | |
1682 size_t size, | |
1683 bool tlab) | |
1684 { | |
1685 if (!UseCMSCollectionPassing && _collectorState > Idling) { | |
1686 // For debugging purposes skip the collection if the state | |
1687 // is not currently idle | |
1688 if (TraceCMSState) { | |
1689 gclog_or_tty->print_cr("Thread " INTPTR_FORMAT " skipped full:%d CMS state %d", | |
1690 Thread::current(), full, _collectorState); | |
1691 } | |
1692 return; | |
1693 } | |
1694 | |
1695 // The following "if" branch is present for defensive reasons. | |
1696 // In the current uses of this interface, it can be replaced with: | |
1697 // assert(!GC_locker.is_active(), "Can't be called otherwise"); | |
1698 // But I am not placing that assert here to allow future | |
1699 // generality in invoking this interface. | |
1700 if (GC_locker::is_active()) { | |
1701 // A consistency test for GC_locker | |
1702 assert(GC_locker::needs_gc(), "Should have been set already"); | |
1703 // Skip this foreground collection, instead | |
1704 // expanding the heap if necessary. | |
1705 // Need the free list locks for the call to free() in compute_new_size() | |
1706 compute_new_size(); | |
1707 return; | |
1708 } | |
1709 acquire_control_and_collect(full, clear_all_soft_refs); | |
1710 _full_gcs_since_conc_gc++; | |
1711 } | |
1712 | |
10405 | 1713 void CMSCollector::request_full_gc(unsigned int full_gc_count, GCCause::Cause cause) { |
0 | 1714 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
1715 unsigned int gc_count = gch->total_full_collections(); | |
1716 if (gc_count == full_gc_count) { | |
1717 MutexLockerEx y(CGC_lock, Mutex::_no_safepoint_check_flag); | |
1718 _full_gc_requested = true; | |
10405 | 1719 _full_gc_cause = cause; |
0 | 1720 CGC_lock->notify(); // nudge CMS thread |
2365
a181f3a124dd
6987703: iCMS: Intermittent hang with gc/gctests/CallGC/CallGC01 and +ExplicitGCInvokesConcurrent
ysr
parents:
2226
diff
changeset
|
1721 } else { |
a181f3a124dd
6987703: iCMS: Intermittent hang with gc/gctests/CallGC/CallGC01 and +ExplicitGCInvokesConcurrent
ysr
parents:
2226
diff
changeset
|
1722 assert(gc_count > full_gc_count, "Error: causal loop"); |
0 | 1723 } |
1724 } | |
1725 | |
10405 | 1726 bool CMSCollector::is_external_interruption() { |
1727 GCCause::Cause cause = GenCollectedHeap::heap()->gc_cause(); | |
1728 return GCCause::is_user_requested_gc(cause) || | |
1729 GCCause::is_serviceability_requested_gc(cause); | |
1730 } | |
1731 | |
1732 void CMSCollector::report_concurrent_mode_interruption() { | |
1733 if (is_external_interruption()) { | |
1734 if (PrintGCDetails) { | |
1735 gclog_or_tty->print(" (concurrent mode interrupted)"); | |
1736 } | |
1737 } else { | |
1738 if (PrintGCDetails) { | |
1739 gclog_or_tty->print(" (concurrent mode failure)"); | |
1740 } | |
1741 _gc_tracer_cm->report_concurrent_mode_failure(); | |
1742 } | |
1743 } | |
1744 | |
0 | 1745 |
1746 // The foreground and background collectors need to coordinate in order | |
1747 // to make sure that they do not mutually interfere with CMS collections. | |
1748 // When a background collection is active, | |
1749 // the foreground collector may need to take over (preempt) and | |
1750 // synchronously complete an ongoing collection. Depending on the | |
1751 // frequency of the background collections and the heap usage | |
1752 // of the application, this preemption can be seldom or frequent. | |
1753 // There are only certain | |
1754 // points in the background collection that the "collection-baton" | |
1755 // can be passed to the foreground collector. | |
1756 // | |
1757 // The foreground collector will wait for the baton before | |
1758 // starting any part of the collection. The foreground collector | |
1759 // will only wait at one location. | |
1760 // | |
1761 // The background collector will yield the baton before starting a new | |
1762 // phase of the collection (e.g., before initial marking, marking from roots, | |
1763 // precleaning, final re-mark, sweep etc.) This is normally done at the head | |
1764 // of the loop which switches the phases. The background collector does some | |
1765 // of the phases (initial mark, final re-mark) with the world stopped. | |
1766 // Because of locking involved in stopping the world, | |
1767 // the foreground collector should not block waiting for the background | |
1768 // collector when it is doing a stop-the-world phase. The background | |
1769 // collector will yield the baton at an additional point just before | |
1770 // it enters a stop-the-world phase. Once the world is stopped, the | |
1771 // background collector checks the phase of the collection. If the | |
1772 // phase has not changed, it proceeds with the collection. If the | |
1773 // phase has changed, it skips that phase of the collection. See | |
1774 // the comments on the use of the Heap_lock in collect_in_background(). | |
1775 // | |
1776 // Variable used in baton passing. | |
1777 // _foregroundGCIsActive - Set to true by the foreground collector when | |
1778 // it wants the baton. The foreground clears it when it has finished | |
1779 // the collection. | |
1780 // _foregroundGCShouldWait - Set to true by the background collector | |
1781 // when it is running. The foreground collector waits while | |
1782 // _foregroundGCShouldWait is true. | |
1783 // CGC_lock - monitor used to protect access to the above variables | |
1784 // and to notify the foreground and background collectors. | |
1785 // _collectorState - current state of the CMS collection. | |
1786 // | |
1787 // The foreground collector | |
1788 // acquires the CGC_lock | |
1789 // sets _foregroundGCIsActive | |
1790 // waits on the CGC_lock for _foregroundGCShouldWait to be false | |
1791 // various locks acquired in preparation for the collection | |
1792 // are released so as not to block the background collector | |
1793 // that is in the midst of a collection | |
1794 // proceeds with the collection | |
1795 // clears _foregroundGCIsActive | |
1796 // returns | |
1797 // | |
1798 // The background collector in a loop iterating on the phases of the | |
1799 // collection | |
1800 // acquires the CGC_lock | |
1801 // sets _foregroundGCShouldWait | |
1802 // if _foregroundGCIsActive is set | |
1803 // clears _foregroundGCShouldWait, notifies _CGC_lock | |
1804 // waits on _CGC_lock for _foregroundGCIsActive to become false | |
1805 // and exits the loop. | |
1806 // otherwise | |
1807 // proceed with that phase of the collection | |
1808 // if the phase is a stop-the-world phase, | |
1809 // yield the baton once more just before enqueueing | |
1810 // the stop-world CMS operation (executed by the VM thread). | |
1811 // returns after all phases of the collection are done | |
1812 // | |
1813 | |
1814 void CMSCollector::acquire_control_and_collect(bool full, | |
1815 bool clear_all_soft_refs) { | |
1816 assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint"); | |
1817 assert(!Thread::current()->is_ConcurrentGC_thread(), | |
1818 "shouldn't try to acquire control from self!"); | |
1819 | |
1820 // Start the protocol for acquiring control of the | |
1821 // collection from the background collector (aka CMS thread). | |
1822 assert(ConcurrentMarkSweepThread::vm_thread_has_cms_token(), | |
1823 "VM thread should have CMS token"); | |
1824 // Remember the possibly interrupted state of an ongoing | |
1825 // concurrent collection | |
1826 CollectorState first_state = _collectorState; | |
1827 | |
1828 // Signal to a possibly ongoing concurrent collection that | |
1829 // we want to do a foreground collection. | |
1830 _foregroundGCIsActive = true; | |
1831 | |
1832 // Disable incremental mode during a foreground collection. | |
1833 ICMSDisabler icms_disabler; | |
1834 | |
1835 // release locks and wait for a notify from the background collector | |
1836 // releasing the locks in only necessary for phases which | |
1837 // do yields to improve the granularity of the collection. | |
1838 assert_lock_strong(bitMapLock()); | |
1839 // We need to lock the Free list lock for the space that we are | |
1840 // currently collecting. | |
1841 assert(haveFreelistLocks(), "Must be holding free list locks"); | |
1842 bitMapLock()->unlock(); | |
1843 releaseFreelistLocks(); | |
1844 { | |
1845 MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag); | |
1846 if (_foregroundGCShouldWait) { | |
1847 // We are going to be waiting for action for the CMS thread; | |
1848 // it had better not be gone (for instance at shutdown)! | |
1849 assert(ConcurrentMarkSweepThread::cmst() != NULL, | |
1850 "CMS thread must be running"); | |
1851 // Wait here until the background collector gives us the go-ahead | |
1852 ConcurrentMarkSweepThread::clear_CMS_flag( | |
1853 ConcurrentMarkSweepThread::CMS_vm_has_token); // release token | |
1854 // Get a possibly blocked CMS thread going: | |
1855 // Note that we set _foregroundGCIsActive true above, | |
1856 // without protection of the CGC_lock. | |
1857 CGC_lock->notify(); | |
1858 assert(!ConcurrentMarkSweepThread::vm_thread_wants_cms_token(), | |
1859 "Possible deadlock"); | |
1860 while (_foregroundGCShouldWait) { | |
1861 // wait for notification | |
1862 CGC_lock->wait(Mutex::_no_safepoint_check_flag); | |
1863 // Possibility of delay/starvation here, since CMS token does | |
1864 // not know to give priority to VM thread? Actually, i think | |
1865 // there wouldn't be any delay/starvation, but the proof of | |
1866 // that "fact" (?) appears non-trivial. XXX 20011219YSR | |
1867 } | |
1868 ConcurrentMarkSweepThread::set_CMS_flag( | |
1869 ConcurrentMarkSweepThread::CMS_vm_has_token); | |
1870 } | |
1871 } | |
1872 // The CMS_token is already held. Get back the other locks. | |
1873 assert(ConcurrentMarkSweepThread::vm_thread_has_cms_token(), | |
1874 "VM thread should have CMS token"); | |
1875 getFreelistLocks(); | |
1876 bitMapLock()->lock_without_safepoint_check(); | |
1877 if (TraceCMSState) { | |
1878 gclog_or_tty->print_cr("CMS foreground collector has asked for control " | |
1879 INTPTR_FORMAT " with first state %d", Thread::current(), first_state); | |
1880 gclog_or_tty->print_cr(" gets control with state %d", _collectorState); | |
1881 } | |
1882 | |
1883 // Check if we need to do a compaction, or if not, whether | |
1884 // we need to start the mark-sweep from scratch. | |
1885 bool should_compact = false; | |
1886 bool should_start_over = false; | |
1887 decide_foreground_collection_type(clear_all_soft_refs, | |
1888 &should_compact, &should_start_over); | |
1889 | |
1890 NOT_PRODUCT( | |
1891 if (RotateCMSCollectionTypes) { | |
1892 if (_cmsGen->debug_collection_type() == | |
1893 ConcurrentMarkSweepGeneration::MSC_foreground_collection_type) { | |
1894 should_compact = true; | |
1895 } else if (_cmsGen->debug_collection_type() == | |
1896 ConcurrentMarkSweepGeneration::MS_foreground_collection_type) { | |
1897 should_compact = false; | |
1898 } | |
1899 } | |
1900 ) | |
1901 | |
10405 | 1902 if (first_state > Idling) { |
1903 report_concurrent_mode_interruption(); | |
0 | 1904 } |
1905 | |
10244
06ab37f08701
8013184: CMS: Call reset_after_compaction() only if a compaction has been done
jmasa
parents:
10243
diff
changeset
|
1906 set_did_compact(should_compact); |
0 | 1907 if (should_compact) { |
1908 // If the collection is being acquired from the background | |
1909 // collector, there may be references on the discovered | |
1910 // references lists that have NULL referents (being those | |
1911 // that were concurrently cleared by a mutator) or | |
1912 // that are no longer active (having been enqueued concurrently | |
1913 // by the mutator). | |
1914 // Scrub the list of those references because Mark-Sweep-Compact | |
1915 // code assumes referents are not NULL and that all discovered | |
1916 // Reference objects are active. | |
1917 ref_processor()->clean_up_discovered_references(); | |
1918 | |
10405 | 1919 if (first_state > Idling) { |
1920 save_heap_summary(); | |
1921 } | |
1922 | |
0 | 1923 do_compaction_work(clear_all_soft_refs); |
1924 | |
1925 // 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
|
1926 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
|
1927 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
|
1928 young_gen->to()->capacity() - |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
1929 young_gen->from()->capacity(); |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
1930 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
1931 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
|
1932 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
|
1933 young_gen->eden()->used(), |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
1934 _cmsGen->max_capacity(), |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
1935 max_eden_size, |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
1936 full, |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
1937 gc_cause, |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
1938 gch->collector_policy()); |
0 | 1939 } else { |
1940 do_mark_sweep_work(clear_all_soft_refs, first_state, | |
1941 should_start_over); | |
1942 } | |
1943 // Reset the expansion cause, now that we just completed | |
1944 // a collection cycle. | |
1945 clear_expansion_cause(); | |
1946 _foregroundGCIsActive = false; | |
1947 return; | |
1948 } | |
1949 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1950 // Resize the tenured generation |
0 | 1951 // after obtaining the free list locks for the |
1952 // two generations. | |
1953 void CMSCollector::compute_new_size() { | |
1954 assert_locked_or_safepoint(Heap_lock); | |
1955 FreelistLocker z(this); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1956 MetaspaceGC::compute_new_size(); |
9072
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
1957 _cmsGen->compute_new_size_free_list(); |
0 | 1958 } |
1959 | |
1960 // A work method used by foreground collection to determine | |
1961 // what type of collection (compacting or not, continuing or fresh) | |
1962 // it should do. | |
1963 // NOTE: the intent is to make UseCMSCompactAtFullCollection | |
1964 // and CMSCompactWhenClearAllSoftRefs the default in the future | |
1965 // and do away with the flags after a suitable period. | |
1966 void CMSCollector::decide_foreground_collection_type( | |
1967 bool clear_all_soft_refs, bool* should_compact, | |
1968 bool* should_start_over) { | |
1969 // Normally, we'll compact only if the UseCMSCompactAtFullCollection | |
1970 // flag is set, and we have either requested a System.gc() or | |
1971 // the number of full gc's since the last concurrent cycle | |
1972 // has exceeded the threshold set by CMSFullGCsBeforeCompaction, | |
1973 // or if an incremental collection has failed | |
1974 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
1975 assert(gch->collector_policy()->is_two_generation_policy(), | |
1976 "You may want to check the correctness of the following"); | |
1977 // Inform cms gen if this was due to partial collection failing. | |
1978 // 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
|
1979 if (gch->incremental_collection_will_fail(false /* don't consult_young */)) { |
0 | 1980 assert(!_cmsGen->incremental_collection_failed(), |
1981 "Should have been noticed, reacted to and cleared"); | |
1982 _cmsGen->set_incremental_collection_failed(); | |
1983 } | |
1984 *should_compact = | |
1985 UseCMSCompactAtFullCollection && | |
1986 ((_full_gcs_since_conc_gc >= CMSFullGCsBeforeCompaction) || | |
1987 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
|
1988 gch->incremental_collection_will_fail(true /* consult_young */)); |
0 | 1989 *should_start_over = false; |
1990 if (clear_all_soft_refs && !*should_compact) { | |
1991 // We are about to do a last ditch collection attempt | |
1992 // so it would normally make sense to do a compaction | |
1993 // to reclaim as much space as possible. | |
1994 if (CMSCompactWhenClearAllSoftRefs) { | |
1995 // Default: The rationale is that in this case either | |
1996 // we are past the final marking phase, in which case | |
1997 // we'd have to start over, or so little has been done | |
1998 // that there's little point in saving that work. Compaction | |
1999 // appears to be the sensible choice in either case. | |
2000 *should_compact = true; | |
2001 } else { | |
2002 // We have been asked to clear all soft refs, but not to | |
2003 // compact. Make sure that we aren't past the final checkpoint | |
2004 // phase, for that is where we process soft refs. If we are already | |
2005 // past that phase, we'll need to redo the refs discovery phase and | |
2006 // if necessary clear soft refs that weren't previously | |
2007 // cleared. We do so by remembering the phase in which | |
2008 // we came in, and if we are past the refs processing | |
2009 // phase, we'll choose to just redo the mark-sweep | |
2010 // collection from scratch. | |
2011 if (_collectorState > FinalMarking) { | |
2012 // We are past the refs processing phase; | |
2013 // start over and do a fresh synchronous CMS cycle | |
2014 _collectorState = Resetting; // skip to reset to start new cycle | |
2015 reset(false /* == !asynch */); | |
2016 *should_start_over = true; | |
2017 } // else we can continue a possibly ongoing current cycle | |
2018 } | |
2019 } | |
2020 } | |
2021 | |
2022 // A work method used by the foreground collector to do | |
2023 // a mark-sweep-compact. | |
2024 void CMSCollector::do_compaction_work(bool clear_all_soft_refs) { | |
2025 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
10405 | 2026 |
2027 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
|
2028 gc_timer->register_gc_start(); |
10405 | 2029 |
2030 SerialOldTracer* gc_tracer = GenMarkSweep::gc_tracer(); | |
2031 gc_tracer->report_gc_start(gch->gc_cause(), gc_timer->gc_start()); | |
2032 | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
2033 GCTraceTime t("CMS:MSC ", PrintGCDetails && Verbose, true, NULL, gc_tracer->gc_id()); |
0 | 2034 if (PrintGC && Verbose && !(GCCause::is_user_requested_gc(gch->gc_cause()))) { |
2035 gclog_or_tty->print_cr("Compact ConcurrentMarkSweepGeneration after %d " | |
2036 "collections passed to foreground collector", _full_gcs_since_conc_gc); | |
2037 } | |
2038 | |
2039 // Sample collection interval time and reset for collection pause. | |
2040 if (UseAdaptiveSizePolicy) { | |
2041 size_policy()->msc_collection_begin(); | |
2042 } | |
2043 | |
2044 // Temporarily widen the span of the weak reference processing to | |
2045 // the entire heap. | |
2046 MemRegion new_span(GenCollectedHeap::heap()->reserved_region()); | |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
2047 ReferenceProcessorSpanMutator rp_mut_span(ref_processor(), new_span); |
0 | 2048 // Temporarily, clear the "is_alive_non_header" field of the |
2049 // reference processor. | |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
2050 ReferenceProcessorIsAliveMutator rp_mut_closure(ref_processor(), NULL); |
0 | 2051 // Temporarily make reference _processing_ single threaded (non-MT). |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
2052 ReferenceProcessorMTProcMutator rp_mut_mt_processing(ref_processor(), false); |
0 | 2053 // Temporarily make refs discovery atomic |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
2054 ReferenceProcessorAtomicMutator rp_mut_atomic(ref_processor(), true); |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
2055 // Temporarily make reference _discovery_ single threaded (non-MT) |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
2056 ReferenceProcessorMTDiscoveryMutator rp_mut_discovery(ref_processor(), false); |
0 | 2057 |
2058 ref_processor()->set_enqueuing_is_done(false); | |
3979
4dfb2df418f2
6484982: G1: process references during evacuation pauses
johnc
parents:
3827
diff
changeset
|
2059 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
|
2060 ref_processor()->setup_policy(clear_all_soft_refs); |
0 | 2061 // If an asynchronous collection finishes, the _modUnionTable is |
2062 // all clear. If we are assuming the collection from an asynchronous | |
2063 // collection, clear the _modUnionTable. | |
2064 assert(_collectorState != Idling || _modUnionTable.isAllClear(), | |
2065 "_modUnionTable should be clear if the baton was not passed"); | |
2066 _modUnionTable.clear_all(); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2067 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
|
2068 "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
|
2069 _ct->klass_rem_set()->clear_mod_union(); |
0 | 2070 |
2071 // We must adjust the allocation statistics being maintained | |
2072 // in the free list space. We do so by reading and clearing | |
2073 // 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
|
2074 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
|
2075 if (_inter_sweep_timer.is_active()) { |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2076 _inter_sweep_timer.stop(); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2077 // 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
|
2078 _cmsGen->cmsSpace()->beginSweepFLCensus((float)(_inter_sweep_timer.seconds()), |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2079 _inter_sweep_estimate.padded_average(), |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2080 _intra_sweep_estimate.padded_average()); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2081 } |
0 | 2082 |
2083 GenMarkSweep::invoke_at_safepoint(_cmsGen->level(), | |
2084 ref_processor(), clear_all_soft_refs); | |
2085 #ifdef ASSERT | |
2086 CompactibleFreeListSpace* cms_space = _cmsGen->cmsSpace(); | |
2087 size_t free_size = cms_space->free(); | |
2088 assert(free_size == | |
2089 pointer_delta(cms_space->end(), cms_space->compaction_top()) | |
2090 * HeapWordSize, | |
2091 "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
|
2092 assert(cms_space->dictionary()->total_chunk_size( |
0 | 2093 debug_only(cms_space->freelistLock())) == 0 || |
2094 cms_space->totalSizeInIndexedFreeLists() == 0, | |
2095 "All the free space should be in a single chunk"); | |
2096 size_t num = cms_space->totalCount(); | |
2097 assert((free_size == 0 && num == 0) || | |
2098 (free_size > 0 && (num == 1 || num == 2)), | |
2099 "There should be at most 2 free chunks after compaction"); | |
2100 #endif // ASSERT | |
2101 _collectorState = Resetting; | |
2102 assert(_restart_addr == NULL, | |
2103 "Should have been NULL'd before baton was passed"); | |
2104 reset(false /* == !asynch */); | |
2105 _cmsGen->reset_after_compaction(); | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
2106 _concurrent_cycles_since_last_unload = 0; |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
2107 |
0 | 2108 // Clear any data recorded in the PLAB chunk arrays. |
2109 if (_survivor_plab_array != NULL) { | |
2110 reset_survivor_plab_arrays(); | |
2111 } | |
2112 | |
2113 // Adjust the per-size allocation stats for the next epoch. | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2114 _cmsGen->cmsSpace()->endSweepFLCensus(sweep_count() /* fake */); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2115 // Restart the "inter sweep timer" for the next epoch. |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2116 _inter_sweep_timer.reset(); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2117 _inter_sweep_timer.start(); |
0 | 2118 |
2119 // Sample collection pause time and reset for collection interval. | |
2120 if (UseAdaptiveSizePolicy) { | |
2121 size_policy()->msc_collection_end(gch->gc_cause()); | |
2122 } | |
2123 | |
13400
86e6d691f2e1
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
13064
diff
changeset
|
2124 gc_timer->register_gc_end(); |
10405 | 2125 |
2126 gc_tracer->report_gc_end(gc_timer->gc_end(), gc_timer->time_partitions()); | |
2127 | |
0 | 2128 // For a mark-sweep-compact, compute_new_size() will be called |
2129 // in the heap's do_collection() method. | |
2130 } | |
2131 | |
2132 // A work method used by the foreground collector to do | |
2133 // a mark-sweep, after taking over from a possibly on-going | |
2134 // concurrent mark-sweep collection. | |
2135 void CMSCollector::do_mark_sweep_work(bool clear_all_soft_refs, | |
2136 CollectorState first_state, bool should_start_over) { | |
2137 if (PrintGC && Verbose) { | |
2138 gclog_or_tty->print_cr("Pass concurrent collection to foreground " | |
2139 "collector with count %d", | |
2140 _full_gcs_since_conc_gc); | |
2141 } | |
2142 switch (_collectorState) { | |
2143 case Idling: | |
2144 if (first_state == Idling || should_start_over) { | |
2145 // The background GC was not active, or should | |
2146 // restarted from scratch; start the cycle. | |
2147 _collectorState = InitialMarking; | |
2148 } | |
2149 // If first_state was not Idling, then a background GC | |
2150 // was in progress and has now finished. No need to do it | |
2151 // again. Leave the state as Idling. | |
2152 break; | |
2153 case Precleaning: | |
2154 // In the foreground case don't do the precleaning since | |
2155 // it is not done concurrently and there is extra work | |
2156 // required. | |
2157 _collectorState = FinalMarking; | |
2158 } | |
10405 | 2159 collect_in_foreground(clear_all_soft_refs, GenCollectedHeap::heap()->gc_cause()); |
0 | 2160 |
2161 // For a mark-sweep, compute_new_size() will be called | |
2162 // in the heap's do_collection() method. | |
2163 } | |
2164 | |
2165 | |
11973
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2166 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
|
2167 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
|
2168 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
|
2169 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
|
2170 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
|
2171 // Eden |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2172 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
|
2173 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
|
2174 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
|
2175 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
|
2176 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
|
2177 "_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
|
2178 _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
|
2179 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
|
2180 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
|
2181 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
|
2182 } |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2183 } |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2184 // Survivor |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2185 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
|
2186 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
|
2187 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
|
2188 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
|
2189 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
|
2190 "_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
|
2191 _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
|
2192 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
|
2193 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
|
2194 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
|
2195 } |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2196 } |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2197 } |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2198 |
0 | 2199 void CMSCollector::getFreelistLocks() const { |
2200 // Get locks for all free lists in all generations that this | |
2201 // collector is responsible for | |
2202 _cmsGen->freelistLock()->lock_without_safepoint_check(); | |
2203 } | |
2204 | |
2205 void CMSCollector::releaseFreelistLocks() const { | |
2206 // Release locks for all free lists in all generations that this | |
2207 // collector is responsible for | |
2208 _cmsGen->freelistLock()->unlock(); | |
2209 } | |
2210 | |
2211 bool CMSCollector::haveFreelistLocks() const { | |
2212 // Check locks for all free lists in all generations that this | |
2213 // collector is responsible for | |
2214 assert_lock_strong(_cmsGen->freelistLock()); | |
2215 PRODUCT_ONLY(ShouldNotReachHere()); | |
2216 return true; | |
2217 } | |
2218 | |
2219 // A utility class that is used by the CMS collector to | |
2220 // temporarily "release" the foreground collector from its | |
2221 // usual obligation to wait for the background collector to | |
2222 // complete an ongoing phase before proceeding. | |
2223 class ReleaseForegroundGC: public StackObj { | |
2224 private: | |
2225 CMSCollector* _c; | |
2226 public: | |
2227 ReleaseForegroundGC(CMSCollector* c) : _c(c) { | |
2228 assert(_c->_foregroundGCShouldWait, "Else should not need to call"); | |
2229 MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag); | |
2230 // allow a potentially blocked foreground collector to proceed | |
2231 _c->_foregroundGCShouldWait = false; | |
2232 if (_c->_foregroundGCIsActive) { | |
2233 CGC_lock->notify(); | |
2234 } | |
2235 assert(!ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
2236 "Possible deadlock"); | |
2237 } | |
2238 | |
2239 ~ReleaseForegroundGC() { | |
2240 assert(!_c->_foregroundGCShouldWait, "Usage protocol violation?"); | |
2241 MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag); | |
2242 _c->_foregroundGCShouldWait = true; | |
2243 } | |
2244 }; | |
2245 | |
2246 // There are separate collect_in_background and collect_in_foreground because of | |
2247 // the different locking requirements of the background collector and the | |
2248 // foreground collector. There was originally an attempt to share | |
2249 // one "collect" method between the background collector and the foreground | |
2250 // collector but the if-then-else required made it cleaner to have | |
2251 // separate methods. | |
10405 | 2252 void CMSCollector::collect_in_background(bool clear_all_soft_refs, GCCause::Cause cause) { |
0 | 2253 assert(Thread::current()->is_ConcurrentGC_thread(), |
2254 "A CMS asynchronous collection is only allowed on a CMS thread."); | |
2255 | |
2256 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
2257 { | |
2258 bool safepoint_check = Mutex::_no_safepoint_check_flag; | |
2259 MutexLockerEx hl(Heap_lock, safepoint_check); | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
2260 FreelistLocker fll(this); |
0 | 2261 MutexLockerEx x(CGC_lock, safepoint_check); |
2262 if (_foregroundGCIsActive || !UseAsyncConcMarkSweepGC) { | |
2263 // The foreground collector is active or we're | |
2264 // not using asynchronous collections. Skip this | |
2265 // background collection. | |
2266 assert(!_foregroundGCShouldWait, "Should be clear"); | |
2267 return; | |
2268 } else { | |
2269 assert(_collectorState == Idling, "Should be idling before start."); | |
2270 _collectorState = InitialMarking; | |
10405 | 2271 register_gc_start(cause); |
0 | 2272 // Reset the expansion cause, now that we are about to begin |
2273 // a new cycle. | |
2274 clear_expansion_cause(); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2275 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2276 // Clear the MetaspaceGC flag since a concurrent collection |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2277 // 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
|
2278 MetaspaceGC::set_should_concurrent_collect(false); |
0 | 2279 } |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
2280 // 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
|
2281 // ensuing concurrent GC cycle. |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
2282 update_should_unload_classes(); |
0 | 2283 _full_gc_requested = false; // acks all outstanding full gc requests |
10405 | 2284 _full_gc_cause = GCCause::_no_gc; |
0 | 2285 // Signal that we are about to start a collection |
2286 gch->increment_total_full_collections(); // ... starting a collection cycle | |
2287 _collection_count_start = gch->total_full_collections(); | |
2288 } | |
2289 | |
2290 // Used for PrintGC | |
2291 size_t prev_used; | |
2292 if (PrintGC && Verbose) { | |
2293 prev_used = _cmsGen->used(); // XXXPERM | |
2294 } | |
2295 | |
2296 // The change of the collection state is normally done at this level; | |
2297 // the exceptions are phases that are executed while the world is | |
2298 // stopped. For those phases the change of state is done while the | |
2299 // world is stopped. For baton passing purposes this allows the | |
2300 // background collector to finish the phase and change state atomically. | |
2301 // The foreground collector cannot wait on a phase that is done | |
2302 // while the world is stopped because the foreground collector already | |
2303 // has the world stopped and would deadlock. | |
2304 while (_collectorState != Idling) { | |
2305 if (TraceCMSState) { | |
2306 gclog_or_tty->print_cr("Thread " INTPTR_FORMAT " in CMS state %d", | |
2307 Thread::current(), _collectorState); | |
2308 } | |
2309 // The foreground collector | |
2310 // holds the Heap_lock throughout its collection. | |
2311 // holds the CMS token (but not the lock) | |
2312 // except while it is waiting for the background collector to yield. | |
2313 // | |
2314 // The foreground collector should be blocked (not for long) | |
2315 // if the background collector is about to start a phase | |
2316 // executed with world stopped. If the background | |
2317 // collector has already started such a phase, the | |
2318 // foreground collector is blocked waiting for the | |
2319 // Heap_lock. The stop-world phases (InitialMarking and FinalMarking) | |
2320 // are executed in the VM thread. | |
2321 // | |
2322 // The locking order is | |
2323 // PendingListLock (PLL) -- if applicable (FinalMarking) | |
2324 // Heap_lock (both this & PLL locked in VM_CMS_Operation::prologue()) | |
2325 // CMS token (claimed in | |
2326 // stop_world_and_do() --> | |
2327 // safepoint_synchronize() --> | |
2328 // CMSThread::synchronize()) | |
2329 | |
2330 { | |
2331 // Check if the FG collector wants us to yield. | |
2332 CMSTokenSync x(true); // is cms thread | |
2333 if (waitForForegroundGC()) { | |
2334 // We yielded to a foreground GC, nothing more to be | |
2335 // done this round. | |
2336 assert(_foregroundGCShouldWait == false, "We set it to false in " | |
2337 "waitForForegroundGC()"); | |
2338 if (TraceCMSState) { | |
2339 gclog_or_tty->print_cr("CMS Thread " INTPTR_FORMAT | |
2340 " exiting collection CMS state %d", | |
2341 Thread::current(), _collectorState); | |
2342 } | |
2343 return; | |
2344 } else { | |
2345 // The background collector can run but check to see if the | |
2346 // foreground collector has done a collection while the | |
2347 // background collector was waiting to get the CGC_lock | |
2348 // above. If yes, break so that _foregroundGCShouldWait | |
2349 // is cleared before returning. | |
2350 if (_collectorState == Idling) { | |
2351 break; | |
2352 } | |
2353 } | |
2354 } | |
2355 | |
2356 assert(_foregroundGCShouldWait, "Foreground collector, if active, " | |
2357 "should be waiting"); | |
2358 | |
2359 switch (_collectorState) { | |
2360 case InitialMarking: | |
2361 { | |
2362 ReleaseForegroundGC x(this); | |
2363 stats().record_cms_begin(); | |
2364 VM_CMS_Initial_Mark initial_mark_op(this); | |
2365 VMThread::execute(&initial_mark_op); | |
2366 } | |
2367 // The collector state may be any legal state at this point | |
2368 // since the background collector may have yielded to the | |
2369 // foreground collector. | |
2370 break; | |
2371 case Marking: | |
2372 // initial marking in checkpointRootsInitialWork has been completed | |
2373 if (markFromRoots(true)) { // we were successful | |
2374 assert(_collectorState == Precleaning, "Collector state should " | |
2375 "have changed"); | |
2376 } else { | |
2377 assert(_foregroundGCIsActive, "Internal state inconsistency"); | |
2378 } | |
2379 break; | |
2380 case Precleaning: | |
2381 if (UseAdaptiveSizePolicy) { | |
2382 size_policy()->concurrent_precleaning_begin(); | |
2383 } | |
2384 // marking from roots in markFromRoots has been completed | |
2385 preclean(); | |
2386 if (UseAdaptiveSizePolicy) { | |
2387 size_policy()->concurrent_precleaning_end(); | |
2388 } | |
2389 assert(_collectorState == AbortablePreclean || | |
2390 _collectorState == FinalMarking, | |
2391 "Collector state should have changed"); | |
2392 break; | |
2393 case AbortablePreclean: | |
2394 if (UseAdaptiveSizePolicy) { | |
2395 size_policy()->concurrent_phases_resume(); | |
2396 } | |
2397 abortable_preclean(); | |
2398 if (UseAdaptiveSizePolicy) { | |
2399 size_policy()->concurrent_precleaning_end(); | |
2400 } | |
2401 assert(_collectorState == FinalMarking, "Collector state should " | |
2402 "have changed"); | |
2403 break; | |
2404 case FinalMarking: | |
2405 { | |
2406 ReleaseForegroundGC x(this); | |
2407 | |
2408 VM_CMS_Final_Remark final_remark_op(this); | |
2409 VMThread::execute(&final_remark_op); | |
935 | 2410 } |
0 | 2411 assert(_foregroundGCShouldWait, "block post-condition"); |
2412 break; | |
2413 case Sweeping: | |
2414 if (UseAdaptiveSizePolicy) { | |
2415 size_policy()->concurrent_sweeping_begin(); | |
2416 } | |
2417 // final marking in checkpointRootsFinal has been completed | |
2418 sweep(true); | |
2419 assert(_collectorState == Resizing, "Collector state change " | |
2420 "to Resizing must be done under the free_list_lock"); | |
2421 _full_gcs_since_conc_gc = 0; | |
2422 | |
2423 // Stop the timers for adaptive size policy for the concurrent phases | |
2424 if (UseAdaptiveSizePolicy) { | |
2425 size_policy()->concurrent_sweeping_end(); | |
2426 size_policy()->concurrent_phases_end(gch->gc_cause(), | |
2427 gch->prev_gen(_cmsGen)->capacity(), | |
2428 _cmsGen->free()); | |
2429 } | |
2430 | |
2431 case Resizing: { | |
2432 // Sweeping has been completed... | |
2433 // At this point the background collection has completed. | |
2434 // Don't move the call to compute_new_size() down | |
2435 // into code that might be executed if the background | |
2436 // collection was preempted. | |
2437 { | |
2438 ReleaseForegroundGC x(this); // unblock FG collection | |
2439 MutexLockerEx y(Heap_lock, Mutex::_no_safepoint_check_flag); | |
2440 CMSTokenSync z(true); // not strictly needed. | |
2441 if (_collectorState == Resizing) { | |
2442 compute_new_size(); | |
10405 | 2443 save_heap_summary(); |
0 | 2444 _collectorState = Resetting; |
2445 } else { | |
2446 assert(_collectorState == Idling, "The state should only change" | |
2447 " because the foreground collector has finished the collection"); | |
2448 } | |
2449 } | |
2450 break; | |
2451 } | |
2452 case Resetting: | |
2453 // CMS heap resizing has been completed | |
2454 reset(true); | |
2455 assert(_collectorState == Idling, "Collector state should " | |
2456 "have changed"); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2457 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2458 MetaspaceGC::set_should_concurrent_collect(false); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2459 |
0 | 2460 stats().record_cms_end(); |
2461 // Don't move the concurrent_phases_end() and compute_new_size() | |
2462 // calls to here because a preempted background collection | |
2463 // has it's state set to "Resetting". | |
2464 break; | |
2465 case Idling: | |
2466 default: | |
2467 ShouldNotReachHere(); | |
2468 break; | |
2469 } | |
2470 if (TraceCMSState) { | |
2471 gclog_or_tty->print_cr(" Thread " INTPTR_FORMAT " done - next CMS state %d", | |
2472 Thread::current(), _collectorState); | |
2473 } | |
2474 assert(_foregroundGCShouldWait, "block post-condition"); | |
2475 } | |
2476 | |
2477 // Should this be in gc_epilogue? | |
2478 collector_policy()->counters()->update_counters(); | |
2479 | |
2480 { | |
2481 // Clear _foregroundGCShouldWait and, in the event that the | |
2482 // foreground collector is waiting, notify it, before | |
2483 // returning. | |
2484 MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag); | |
2485 _foregroundGCShouldWait = false; | |
2486 if (_foregroundGCIsActive) { | |
2487 CGC_lock->notify(); | |
2488 } | |
2489 assert(!ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
2490 "Possible deadlock"); | |
2491 } | |
2492 if (TraceCMSState) { | |
2493 gclog_or_tty->print_cr("CMS Thread " INTPTR_FORMAT | |
2494 " exiting collection CMS state %d", | |
2495 Thread::current(), _collectorState); | |
2496 } | |
2497 if (PrintGC && Verbose) { | |
2498 _cmsGen->print_heap_change(prev_used); | |
2499 } | |
2500 } | |
2501 | |
10405 | 2502 void CMSCollector::register_foreground_gc_start(GCCause::Cause cause) { |
2503 if (!_cms_start_registered) { | |
2504 register_gc_start(cause); | |
2505 } | |
2506 } | |
2507 | |
2508 void CMSCollector::register_gc_start(GCCause::Cause cause) { | |
2509 _cms_start_registered = true; | |
13400
86e6d691f2e1
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
13064
diff
changeset
|
2510 _gc_timer_cm->register_gc_start(); |
10405 | 2511 _gc_tracer_cm->report_gc_start(cause, _gc_timer_cm->gc_start()); |
2512 } | |
2513 | |
2514 void CMSCollector::register_gc_end() { | |
2515 if (_cms_start_registered) { | |
2516 report_heap_summary(GCWhen::AfterGC); | |
2517 | |
13400
86e6d691f2e1
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
13064
diff
changeset
|
2518 _gc_timer_cm->register_gc_end(); |
10405 | 2519 _gc_tracer_cm->report_gc_end(_gc_timer_cm->gc_end(), _gc_timer_cm->time_partitions()); |
2520 _cms_start_registered = false; | |
2521 } | |
2522 } | |
2523 | |
2524 void CMSCollector::save_heap_summary() { | |
2525 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
2526 _last_heap_summary = gch->create_heap_summary(); | |
2527 _last_metaspace_summary = gch->create_metaspace_summary(); | |
2528 } | |
2529 | |
2530 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
|
2531 _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
|
2532 _gc_tracer_cm->report_metaspace_summary(when, _last_metaspace_summary); |
10405 | 2533 } |
2534 | |
2535 void CMSCollector::collect_in_foreground(bool clear_all_soft_refs, GCCause::Cause cause) { | |
0 | 2536 assert(_foregroundGCIsActive && !_foregroundGCShouldWait, |
2537 "Foreground collector should be waiting, not executing"); | |
2538 assert(Thread::current()->is_VM_thread(), "A foreground collection" | |
2539 "may only be done by the VM Thread with the world stopped"); | |
2540 assert(ConcurrentMarkSweepThread::vm_thread_has_cms_token(), | |
2541 "VM thread should have CMS token"); | |
2542 | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
2543 // 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
|
2544 const GCId gc_id = _collectorState == InitialMarking ? GCId::peek() : _gc_tracer_cm->gc_id(); |
10405 | 2545 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
|
2546 true, NULL, gc_id);) |
0 | 2547 if (UseAdaptiveSizePolicy) { |
2548 size_policy()->ms_collection_begin(); | |
2549 } | |
22294
d86b226e331a
Enable derived oop processing by the GC with JVMCI
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
20804
diff
changeset
|
2550 #if defined(COMPILER2) || defined(JVMCI) |
d86b226e331a
Enable derived oop processing by the GC with JVMCI
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
20804
diff
changeset
|
2551 DerivedPointerTableDeactivate dpt_deact; |
d86b226e331a
Enable derived oop processing by the GC with JVMCI
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
20804
diff
changeset
|
2552 #endif |
0 | 2553 |
2554 HandleMark hm; // Discard invalid handles created during verification | |
2555 | |
2556 if (VerifyBeforeGC && | |
2557 GenCollectedHeap::heap()->total_collections() >= VerifyGCStartAt) { | |
6865
4202510ee0fe
8000831: Heap verification output incorrect/incomplete
johnc
parents:
6787
diff
changeset
|
2558 Universe::verify(); |
0 | 2559 } |
2560 | |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
2561 // 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
|
2562 ref_processor()->setup_policy(clear_all_soft_refs); |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
2563 |
13064
592d8b01fedd
8024483: assertion failure: (!mirror_alive || loader_alive) failed:
jmasa
parents:
13063
diff
changeset
|
2564 // Decide if class unloading should be done |
592d8b01fedd
8024483: assertion failure: (!mirror_alive || loader_alive) failed:
jmasa
parents:
13063
diff
changeset
|
2565 update_should_unload_classes(); |
592d8b01fedd
8024483: assertion failure: (!mirror_alive || loader_alive) failed:
jmasa
parents:
13063
diff
changeset
|
2566 |
0 | 2567 bool init_mark_was_synchronous = false; // until proven otherwise |
2568 while (_collectorState != Idling) { | |
2569 if (TraceCMSState) { | |
2570 gclog_or_tty->print_cr("Thread " INTPTR_FORMAT " in CMS state %d", | |
2571 Thread::current(), _collectorState); | |
2572 } | |
2573 switch (_collectorState) { | |
2574 case InitialMarking: | |
10405 | 2575 register_foreground_gc_start(cause); |
0 | 2576 init_mark_was_synchronous = true; // fact to be exploited in re-mark |
2577 checkpointRootsInitial(false); | |
2578 assert(_collectorState == Marking, "Collector state should have changed" | |
2579 " within checkpointRootsInitial()"); | |
2580 break; | |
2581 case Marking: | |
2582 // initial marking in checkpointRootsInitialWork has been completed | |
2583 if (VerifyDuringGC && | |
2584 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
|
2585 Universe::verify("Verify before initial mark: "); |
0 | 2586 } |
2587 { | |
2588 bool res = markFromRoots(false); | |
2589 assert(res && _collectorState == FinalMarking, "Collector state should " | |
2590 "have changed"); | |
2591 break; | |
2592 } | |
2593 case FinalMarking: | |
2594 if (VerifyDuringGC && | |
2595 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
|
2596 Universe::verify("Verify before re-mark: "); |
0 | 2597 } |
2598 checkpointRootsFinal(false, clear_all_soft_refs, | |
2599 init_mark_was_synchronous); | |
2600 assert(_collectorState == Sweeping, "Collector state should not " | |
2601 "have changed within checkpointRootsFinal()"); | |
2602 break; | |
2603 case Sweeping: | |
2604 // final marking in checkpointRootsFinal has been completed | |
2605 if (VerifyDuringGC && | |
2606 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
|
2607 Universe::verify("Verify before sweep: "); |
0 | 2608 } |
2609 sweep(false); | |
2610 assert(_collectorState == Resizing, "Incorrect state"); | |
2611 break; | |
2612 case Resizing: { | |
2613 // Sweeping has been completed; the actual resize in this case | |
2614 // is done separately; nothing to be done in this state. | |
2615 _collectorState = Resetting; | |
2616 break; | |
2617 } | |
2618 case Resetting: | |
2619 // The heap has been resized. | |
2620 if (VerifyDuringGC && | |
2621 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
|
2622 Universe::verify("Verify before reset: "); |
0 | 2623 } |
10405 | 2624 save_heap_summary(); |
0 | 2625 reset(false); |
2626 assert(_collectorState == Idling, "Collector state should " | |
2627 "have changed"); | |
2628 break; | |
2629 case Precleaning: | |
2630 case AbortablePreclean: | |
2631 // Elide the preclean phase | |
2632 _collectorState = FinalMarking; | |
2633 break; | |
2634 default: | |
2635 ShouldNotReachHere(); | |
2636 } | |
2637 if (TraceCMSState) { | |
2638 gclog_or_tty->print_cr(" Thread " INTPTR_FORMAT " done - next CMS state %d", | |
2639 Thread::current(), _collectorState); | |
2640 } | |
2641 } | |
2642 | |
2643 if (UseAdaptiveSizePolicy) { | |
2644 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
2645 size_policy()->ms_collection_end(gch->gc_cause()); | |
2646 } | |
2647 | |
2648 if (VerifyAfterGC && | |
2649 GenCollectedHeap::heap()->total_collections() >= VerifyGCStartAt) { | |
6865
4202510ee0fe
8000831: Heap verification output incorrect/incomplete
johnc
parents:
6787
diff
changeset
|
2650 Universe::verify(); |
0 | 2651 } |
2652 if (TraceCMSState) { | |
2653 gclog_or_tty->print_cr("CMS Thread " INTPTR_FORMAT | |
2654 " exiting collection CMS state %d", | |
2655 Thread::current(), _collectorState); | |
2656 } | |
2657 } | |
2658 | |
2659 bool CMSCollector::waitForForegroundGC() { | |
2660 bool res = false; | |
2661 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
2662 "CMS thread should have CMS token"); | |
2663 // Block the foreground collector until the | |
2664 // background collectors decides whether to | |
2665 // yield. | |
2666 MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag); | |
2667 _foregroundGCShouldWait = true; | |
2668 if (_foregroundGCIsActive) { | |
2669 // The background collector yields to the | |
2670 // foreground collector and returns a value | |
2671 // indicating that it has yielded. The foreground | |
2672 // collector can proceed. | |
2673 res = true; | |
2674 _foregroundGCShouldWait = false; | |
2675 ConcurrentMarkSweepThread::clear_CMS_flag( | |
2676 ConcurrentMarkSweepThread::CMS_cms_has_token); | |
2677 ConcurrentMarkSweepThread::set_CMS_flag( | |
2678 ConcurrentMarkSweepThread::CMS_cms_wants_token); | |
2679 // Get a possibly blocked foreground thread going | |
2680 CGC_lock->notify(); | |
2681 if (TraceCMSState) { | |
2682 gclog_or_tty->print_cr("CMS Thread " INTPTR_FORMAT " waiting at CMS state %d", | |
2683 Thread::current(), _collectorState); | |
2684 } | |
2685 while (_foregroundGCIsActive) { | |
2686 CGC_lock->wait(Mutex::_no_safepoint_check_flag); | |
2687 } | |
2688 ConcurrentMarkSweepThread::set_CMS_flag( | |
2689 ConcurrentMarkSweepThread::CMS_cms_has_token); | |
2690 ConcurrentMarkSweepThread::clear_CMS_flag( | |
2691 ConcurrentMarkSweepThread::CMS_cms_wants_token); | |
2692 } | |
2693 if (TraceCMSState) { | |
2694 gclog_or_tty->print_cr("CMS Thread " INTPTR_FORMAT " continuing at CMS state %d", | |
2695 Thread::current(), _collectorState); | |
2696 } | |
2697 return res; | |
2698 } | |
2699 | |
2700 // Because of the need to lock the free lists and other structures in | |
2701 // the collector, common to all the generations that the collector is | |
2702 // collecting, we need the gc_prologues of individual CMS generations | |
2703 // delegate to their collector. It may have been simpler had the | |
2704 // current infrastructure allowed one to call a prologue on a | |
2705 // collector. In the absence of that we have the generation's | |
2706 // prologue delegate to the collector, which delegates back | |
2707 // some "local" work to a worker method in the individual generations | |
2708 // that it's responsible for collecting, while itself doing any | |
2709 // work common to all generations it's responsible for. A similar | |
2710 // comment applies to the gc_epilogue()'s. | |
2711 // The role of the varaible _between_prologue_and_epilogue is to | |
2712 // enforce the invocation protocol. | |
2713 void CMSCollector::gc_prologue(bool full) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2714 // Call gc_prologue_work() for the CMSGen |
0 | 2715 // we are responsible for. |
2716 | |
2717 // The following locking discipline assumes that we are only called | |
2718 // when the world is stopped. | |
2719 assert(SafepointSynchronize::is_at_safepoint(), "world is stopped assumption"); | |
2720 | |
2721 // 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
|
2722 // "generations" that it's responsible |
0 | 2723 // for. |
2724 | |
2725 assert( Thread::current()->is_VM_thread() | |
2726 || ( CMSScavengeBeforeRemark | |
2727 && Thread::current()->is_ConcurrentGC_thread()), | |
2728 "Incorrect thread type for prologue execution"); | |
2729 | |
2730 if (_between_prologue_and_epilogue) { | |
2731 // We have already been invoked; this is a gc_prologue delegation | |
2732 // from yet another CMS generation that we are responsible for, just | |
2733 // ignore it since all relevant work has already been done. | |
2734 return; | |
2735 } | |
2736 | |
2737 // set a bit saying prologue has been called; cleared in epilogue | |
2738 _between_prologue_and_epilogue = true; | |
2739 // 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
|
2740 // for each CMSGen. |
0 | 2741 |
2742 getFreelistLocks(); // gets free list locks on constituent spaces | |
2743 bitMapLock()->lock_without_safepoint_check(); | |
2744 | |
2745 // 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
|
2746 bool duringMarking = _collectorState >= Marking |
0 | 2747 && _collectorState < Sweeping; |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2748 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2749 // 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
|
2750 // 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
|
2751 // 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
|
2752 // modified klasses. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2753 if (duringMarking) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2754 _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
|
2755 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2756 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2757 bool registerClosure = duringMarking; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2758 |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
2759 ModUnionClosure* muc = CollectedHeap::use_parallel_gc_threads() ? |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
2760 &_modUnionClosurePar |
0 | 2761 : &_modUnionClosure; |
2762 _cmsGen->gc_prologue_work(full, registerClosure, muc); | |
2763 | |
2764 if (!full) { | |
2765 stats().record_gc0_begin(); | |
2766 } | |
2767 } | |
2768 | |
2769 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
|
2770 |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
2771 _capacity_at_prologue = capacity(); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
2772 _used_at_prologue = used(); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
2773 |
0 | 2774 // Delegate to CMScollector which knows how to coordinate between |
2775 // this and any other CMS generations that it is responsible for | |
2776 // collecting. | |
2777 collector()->gc_prologue(full); | |
2778 } | |
2779 | |
2780 // This is a "private" interface for use by this generation's CMSCollector. | |
2781 // Not to be called directly by any other entity (for instance, | |
2782 // GenCollectedHeap, which calls the "public" gc_prologue method above). | |
2783 void ConcurrentMarkSweepGeneration::gc_prologue_work(bool full, | |
2784 bool registerClosure, ModUnionClosure* modUnionClosure) { | |
2785 assert(!incremental_collection_failed(), "Shouldn't be set yet"); | |
2786 assert(cmsSpace()->preconsumptionDirtyCardClosure() == NULL, | |
2787 "Should be NULL"); | |
2788 if (registerClosure) { | |
2789 cmsSpace()->setPreconsumptionDirtyCardClosure(modUnionClosure); | |
2790 } | |
2791 cmsSpace()->gc_prologue(); | |
2792 // Clear stat counters | |
2793 NOT_PRODUCT( | |
2794 assert(_numObjectsPromoted == 0, "check"); | |
2795 assert(_numWordsPromoted == 0, "check"); | |
2796 if (Verbose && PrintGC) { | |
2797 gclog_or_tty->print("Allocated "SIZE_FORMAT" objects, " | |
2798 SIZE_FORMAT" bytes concurrently", | |
2799 _numObjectsAllocated, _numWordsAllocated*sizeof(HeapWord)); | |
2800 } | |
2801 _numObjectsAllocated = 0; | |
2802 _numWordsAllocated = 0; | |
2803 ) | |
2804 } | |
2805 | |
2806 void CMSCollector::gc_epilogue(bool full) { | |
2807 // The following locking discipline assumes that we are only called | |
2808 // when the world is stopped. | |
2809 assert(SafepointSynchronize::is_at_safepoint(), | |
2810 "world is stopped assumption"); | |
2811 | |
2812 // Currently the CMS epilogue (see CompactibleFreeListSpace) merely checks | |
2813 // if linear allocation blocks need to be appropriately marked to allow the | |
2814 // the blocks to be parsable. We also check here whether we need to nudge the | |
2815 // CMS collector thread to start a new cycle (if it's not already active). | |
2816 assert( Thread::current()->is_VM_thread() | |
2817 || ( CMSScavengeBeforeRemark | |
2818 && Thread::current()->is_ConcurrentGC_thread()), | |
2819 "Incorrect thread type for epilogue execution"); | |
2820 | |
2821 if (!_between_prologue_and_epilogue) { | |
2822 // We have already been invoked; this is a gc_epilogue delegation | |
2823 // from yet another CMS generation that we are responsible for, just | |
2824 // ignore it since all relevant work has already been done. | |
2825 return; | |
2826 } | |
2827 assert(haveFreelistLocks(), "must have freelist locks"); | |
2828 assert_lock_strong(bitMapLock()); | |
2829 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2830 _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
|
2831 |
0 | 2832 _cmsGen->gc_epilogue_work(full); |
2833 | |
2834 if (_collectorState == AbortablePreclean || _collectorState == Precleaning) { | |
2835 // in case sampling was not already enabled, enable it | |
2836 _start_sampling = true; | |
2837 } | |
2838 // reset _eden_chunk_array so sampling starts afresh | |
2839 _eden_chunk_index = 0; | |
2840 | |
2841 size_t cms_used = _cmsGen->cmsSpace()->used(); | |
2842 | |
2843 // update performance counters - this uses a special version of | |
2844 // update_counters() that allows the utilization to be passed as a | |
2845 // parameter, avoiding multiple calls to used(). | |
2846 // | |
2847 _cmsGen->update_counters(cms_used); | |
2848 | |
2849 if (CMSIncrementalMode) { | |
2850 icms_update_allocation_limits(); | |
2851 } | |
2852 | |
2853 bitMapLock()->unlock(); | |
2854 releaseFreelistLocks(); | |
2855 | |
3799
48048b59a551
7061204: clean the chunk table synchronously in embedded builds
jcoomes
parents:
3405
diff
changeset
|
2856 if (!CleanChunkPoolAsync) { |
48048b59a551
7061204: clean the chunk table synchronously in embedded builds
jcoomes
parents:
3405
diff
changeset
|
2857 Chunk::clean_chunk_pool(); |
48048b59a551
7061204: clean the chunk table synchronously in embedded builds
jcoomes
parents:
3405
diff
changeset
|
2858 } |
48048b59a551
7061204: clean the chunk table synchronously in embedded builds
jcoomes
parents:
3405
diff
changeset
|
2859 |
10244
06ab37f08701
8013184: CMS: Call reset_after_compaction() only if a compaction has been done
jmasa
parents:
10243
diff
changeset
|
2860 set_did_compact(false); |
0 | 2861 _between_prologue_and_epilogue = false; // ready for next cycle |
2862 } | |
2863 | |
2864 void ConcurrentMarkSweepGeneration::gc_epilogue(bool full) { | |
2865 collector()->gc_epilogue(full); | |
2866 | |
2867 // Also reset promotion tracking in par gc thread states. | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
2868 if (CollectedHeap::use_parallel_gc_threads()) { |
0 | 2869 for (uint i = 0; i < ParallelGCThreads; i++) { |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2870 _par_gc_thread_states[i]->promo.stopTrackingPromotions(i); |
0 | 2871 } |
2872 } | |
2873 } | |
2874 | |
2875 void ConcurrentMarkSweepGeneration::gc_epilogue_work(bool full) { | |
2876 assert(!incremental_collection_failed(), "Should have been cleared"); | |
2877 cmsSpace()->setPreconsumptionDirtyCardClosure(NULL); | |
2878 cmsSpace()->gc_epilogue(); | |
2879 // Print stat counters | |
2880 NOT_PRODUCT( | |
2881 assert(_numObjectsAllocated == 0, "check"); | |
2882 assert(_numWordsAllocated == 0, "check"); | |
2883 if (Verbose && PrintGC) { | |
2884 gclog_or_tty->print("Promoted "SIZE_FORMAT" objects, " | |
2885 SIZE_FORMAT" bytes", | |
2886 _numObjectsPromoted, _numWordsPromoted*sizeof(HeapWord)); | |
2887 } | |
2888 _numObjectsPromoted = 0; | |
2889 _numWordsPromoted = 0; | |
2890 ) | |
2891 | |
2892 if (PrintGC && Verbose) { | |
2893 // Call down the chain in contiguous_available needs the freelistLock | |
2894 // so print this out before releasing the freeListLock. | |
2895 gclog_or_tty->print(" Contiguous available "SIZE_FORMAT" bytes ", | |
2896 contiguous_available()); | |
2897 } | |
2898 } | |
2899 | |
2900 #ifndef PRODUCT | |
2901 bool CMSCollector::have_cms_token() { | |
2902 Thread* thr = Thread::current(); | |
2903 if (thr->is_VM_thread()) { | |
2904 return ConcurrentMarkSweepThread::vm_thread_has_cms_token(); | |
2905 } else if (thr->is_ConcurrentGC_thread()) { | |
2906 return ConcurrentMarkSweepThread::cms_thread_has_cms_token(); | |
2907 } else if (thr->is_GC_task_thread()) { | |
2908 return ConcurrentMarkSweepThread::vm_thread_has_cms_token() && | |
2909 ParGCRareEvent_lock->owned_by_self(); | |
2910 } | |
2911 return false; | |
2912 } | |
2913 #endif | |
2914 | |
2915 // Check reachability of the given heap address in CMS generation, | |
2916 // treating all other generations as roots. | |
2917 bool CMSCollector::is_cms_reachable(HeapWord* addr) { | |
2918 // We could "guarantee" below, rather than assert, but i'll | |
2919 // leave these as "asserts" so that an adventurous debugger | |
2920 // could try this in the product build provided some subset of | |
2921 // the conditions were met, provided they were intersted in the | |
2922 // results and knew that the computation below wouldn't interfere | |
2923 // with other concurrent computations mutating the structures | |
2924 // being read or written. | |
2925 assert(SafepointSynchronize::is_at_safepoint(), | |
2926 "Else mutations in object graph will make answer suspect"); | |
2927 assert(have_cms_token(), "Should hold cms token"); | |
2928 assert(haveFreelistLocks(), "must hold free list locks"); | |
2929 assert_lock_strong(bitMapLock()); | |
2930 | |
2931 // Clear the marking bit map array before starting, but, just | |
2932 // for kicks, first report if the given address is already marked | |
2933 gclog_or_tty->print_cr("Start: Address 0x%x is%s marked", addr, | |
2934 _markBitMap.isMarked(addr) ? "" : " not"); | |
2935 | |
2936 if (verify_after_remark()) { | |
2937 MutexLockerEx x(verification_mark_bm()->lock(), Mutex::_no_safepoint_check_flag); | |
2938 bool result = verification_mark_bm()->isMarked(addr); | |
2939 gclog_or_tty->print_cr("TransitiveMark: Address 0x%x %s marked", addr, | |
2940 result ? "IS" : "is NOT"); | |
2941 return result; | |
2942 } else { | |
2943 gclog_or_tty->print_cr("Could not compute result"); | |
2944 return false; | |
2945 } | |
2946 } | |
2947 | |
9076
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2948 |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2949 void |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2950 CMSCollector::print_on_error(outputStream* st) { |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2951 CMSCollector* collector = ConcurrentMarkSweepGeneration::_collector; |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2952 if (collector != NULL) { |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2953 CMSBitMap* bitmap = &collector->_markBitMap; |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2954 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
|
2955 bitmap->print_on_error(st, " Bits: "); |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2956 |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2957 st->cr(); |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2958 |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2959 CMSBitMap* mut_bitmap = &collector->_modUnionTable; |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2960 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
|
2961 mut_bitmap->print_on_error(st, " Bits: "); |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2962 } |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2963 } |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2964 |
0 | 2965 //////////////////////////////////////////////////////// |
2966 // CMS Verification Support | |
2967 //////////////////////////////////////////////////////// | |
2968 // Following the remark phase, the following invariant | |
2969 // should hold -- each object in the CMS heap which is | |
2970 // marked in markBitMap() should be marked in the verification_mark_bm(). | |
2971 | |
2972 class VerifyMarkedClosure: public BitMapClosure { | |
2973 CMSBitMap* _marks; | |
2974 bool _failed; | |
2975 | |
2976 public: | |
2977 VerifyMarkedClosure(CMSBitMap* bm): _marks(bm), _failed(false) {} | |
2978 | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
2979 bool do_bit(size_t offset) { |
0 | 2980 HeapWord* addr = _marks->offsetToHeapWord(offset); |
2981 if (!_marks->isMarked(addr)) { | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2982 oop(addr)->print_on(gclog_or_tty); |
0 | 2983 gclog_or_tty->print_cr(" ("INTPTR_FORMAT" should have been marked)", addr); |
2984 _failed = true; | |
2985 } | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
2986 return true; |
0 | 2987 } |
2988 | |
2989 bool failed() { return _failed; } | |
2990 }; | |
2991 | |
10186
b06ac540229e
8013132: Add a flag to turn off the output of the verbose verification code
stefank
parents:
10180
diff
changeset
|
2992 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
|
2993 if (!silent) gclog_or_tty->print(" [Verifying CMS Marking... "); |
0 | 2994 MutexLockerEx ml(verification_mark_bm()->lock(), Mutex::_no_safepoint_check_flag); |
2995 static bool init = false; | |
2996 | |
2997 assert(SafepointSynchronize::is_at_safepoint(), | |
2998 "Else mutations in object graph will make answer suspect"); | |
2999 assert(have_cms_token(), | |
3000 "Else there may be mutual interference in use of " | |
3001 " verification data structures"); | |
3002 assert(_collectorState > Marking && _collectorState <= Sweeping, | |
3003 "Else marking info checked here may be obsolete"); | |
3004 assert(haveFreelistLocks(), "must hold free list locks"); | |
3005 assert_lock_strong(bitMapLock()); | |
3006 | |
3007 | |
3008 // Allocate marking bit map if not already allocated | |
3009 if (!init) { // first time | |
3010 if (!verification_mark_bm()->allocate(_span)) { | |
3011 return false; | |
3012 } | |
3013 init = true; | |
3014 } | |
3015 | |
3016 assert(verification_mark_stack()->isEmpty(), "Should be empty"); | |
3017 | |
3018 // Turn off refs discovery -- so we will be tracing through refs. | |
3019 // This is as intended, because by this time | |
3020 // GC must already have cleared any refs that need to be cleared, | |
3021 // and traced those that need to be marked; moreover, | |
3022 // the marking done here is not going to intefere in any | |
3023 // way with the marking information used by GC. | |
3024 NoRefDiscovery no_discovery(ref_processor()); | |
3025 | |
22294
d86b226e331a
Enable derived oop processing by the GC with JVMCI
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
20804
diff
changeset
|
3026 #if defined(COMPILER2) || defined(JVMCI) |
d86b226e331a
Enable derived oop processing by the GC with JVMCI
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
20804
diff
changeset
|
3027 DerivedPointerTableDeactivate dpt_deact; |
d86b226e331a
Enable derived oop processing by the GC with JVMCI
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
20804
diff
changeset
|
3028 #endif |
0 | 3029 |
3030 // Clear any marks from a previous round | |
3031 verification_mark_bm()->clear_all(); | |
3032 assert(verification_mark_stack()->isEmpty(), "markStack should be empty"); | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
3033 verify_work_stacks_empty(); |
0 | 3034 |
3035 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
3036 gch->ensure_parsability(false); // fill TLABs, but no need to retire them | |
3037 // Update the saved marks which may affect the root scans. | |
3038 gch->save_marks(); | |
3039 | |
3040 if (CMSRemarkVerifyVariant == 1) { | |
3041 // In this first variant of verification, we complete | |
3042 // all marking, then check if the new marks-verctor is | |
3043 // a subset of the CMS marks-vector. | |
3044 verify_after_remark_work_1(); | |
3045 } else if (CMSRemarkVerifyVariant == 2) { | |
3046 // In this second variant of verification, we flag an error | |
3047 // (i.e. an object reachable in the new marks-vector not reachable | |
3048 // in the CMS marks-vector) immediately, also indicating the | |
3049 // identify of an object (A) that references the unmarked object (B) -- | |
3050 // presumably, a mutation to A failed to be picked up by preclean/remark? | |
3051 verify_after_remark_work_2(); | |
3052 } else { | |
3053 warning("Unrecognized value %d for CMSRemarkVerifyVariant", | |
3054 CMSRemarkVerifyVariant); | |
3055 } | |
10186
b06ac540229e
8013132: Add a flag to turn off the output of the verbose verification code
stefank
parents:
10180
diff
changeset
|
3056 if (!silent) gclog_or_tty->print(" done] "); |
0 | 3057 return true; |
3058 } | |
3059 | |
3060 void CMSCollector::verify_after_remark_work_1() { | |
3061 ResourceMark rm; | |
3062 HandleMark hm; | |
3063 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
3064 | |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3065 // 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
|
3066 ClassLoaderDataGraph::clear_claimed_marks(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3067 |
0 | 3068 // 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
|
3069 MarkRefsIntoClosure notOlder(_span, verification_mark_bm()); |
0 | 3070 gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel. |
3071 | |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3072 gch->gen_process_roots(_cmsGen->level(), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3073 true, // younger gens are roots |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3074 true, // activate StrongRootsScope |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3075 SharedHeap::ScanningOption(roots_scanning_options()), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3076 should_unload_classes(), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3077 ¬Older, |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3078 NULL, |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3079 NULL); // SSS: Provide correct closure |
0 | 3080 |
3081 // Now mark from the roots | |
3082 MarkFromRootsClosure markFromRootsClosure(this, _span, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3083 verification_mark_bm(), verification_mark_stack(), |
0 | 3084 false /* don't yield */, true /* verifying */); |
3085 assert(_restart_addr == NULL, "Expected pre-condition"); | |
3086 verification_mark_bm()->iterate(&markFromRootsClosure); | |
3087 while (_restart_addr != NULL) { | |
3088 // Deal with stack overflow: by restarting at the indicated | |
3089 // address. | |
3090 HeapWord* ra = _restart_addr; | |
3091 markFromRootsClosure.reset(ra); | |
3092 _restart_addr = NULL; | |
3093 verification_mark_bm()->iterate(&markFromRootsClosure, ra, _span.end()); | |
3094 } | |
3095 assert(verification_mark_stack()->isEmpty(), "Should have been drained"); | |
3096 verify_work_stacks_empty(); | |
3097 | |
3098 // Marking completed -- now verify that each bit marked in | |
3099 // verification_mark_bm() is also marked in markBitMap(); flag all | |
3100 // errors by printing corresponding objects. | |
3101 VerifyMarkedClosure vcl(markBitMap()); | |
3102 verification_mark_bm()->iterate(&vcl); | |
3103 if (vcl.failed()) { | |
3104 gclog_or_tty->print("Verification failed"); | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
3105 Universe::heap()->print_on(gclog_or_tty); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
3106 fatal("CMS: failed marking verification after remark"); |
0 | 3107 } |
3108 } | |
3109 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3110 class VerifyKlassOopsKlassClosure : public KlassClosure { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3111 class VerifyKlassOopsClosure : public OopClosure { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3112 CMSBitMap* _bitmap; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3113 public: |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3114 VerifyKlassOopsClosure(CMSBitMap* bitmap) : _bitmap(bitmap) { } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3115 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
|
3116 void do_oop(narrowOop* p) { ShouldNotReachHere(); } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3117 } _oop_closure; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3118 public: |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3119 VerifyKlassOopsKlassClosure(CMSBitMap* bitmap) : _oop_closure(bitmap) {} |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3120 void do_klass(Klass* k) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3121 k->oops_do(&_oop_closure); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3122 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3123 }; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3124 |
0 | 3125 void CMSCollector::verify_after_remark_work_2() { |
3126 ResourceMark rm; | |
3127 HandleMark hm; | |
3128 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
3129 | |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3130 // 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
|
3131 ClassLoaderDataGraph::clear_claimed_marks(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3132 |
0 | 3133 // Mark from roots one level into CMS |
3134 MarkRefsIntoVerifyClosure notOlder(_span, verification_mark_bm(), | |
994
753cf9794df9
6885169: merge of 4957990 and 6863023 causes conflict on do_nmethods
jrose
parents:
993
diff
changeset
|
3135 markBitMap()); |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3136 CLDToOopClosure cld_closure(¬Older, true); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3137 |
0 | 3138 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
|
3139 |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3140 gch->gen_process_roots(_cmsGen->level(), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3141 true, // younger gens are roots |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3142 true, // activate StrongRootsScope |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3143 SharedHeap::ScanningOption(roots_scanning_options()), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3144 should_unload_classes(), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3145 ¬Older, |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3146 NULL, |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3147 &cld_closure); |
0 | 3148 |
3149 // Now mark from the roots | |
3150 MarkFromRootsVerifyClosure markFromRootsClosure(this, _span, | |
3151 verification_mark_bm(), markBitMap(), verification_mark_stack()); | |
3152 assert(_restart_addr == NULL, "Expected pre-condition"); | |
3153 verification_mark_bm()->iterate(&markFromRootsClosure); | |
3154 while (_restart_addr != NULL) { | |
3155 // Deal with stack overflow: by restarting at the indicated | |
3156 // address. | |
3157 HeapWord* ra = _restart_addr; | |
3158 markFromRootsClosure.reset(ra); | |
3159 _restart_addr = NULL; | |
3160 verification_mark_bm()->iterate(&markFromRootsClosure, ra, _span.end()); | |
3161 } | |
3162 assert(verification_mark_stack()->isEmpty(), "Should have been drained"); | |
3163 verify_work_stacks_empty(); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3164 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3165 VerifyKlassOopsKlassClosure verify_klass_oops(verification_mark_bm()); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3166 ClassLoaderDataGraph::classes_do(&verify_klass_oops); |
0 | 3167 |
3168 // Marking completed -- now verify that each bit marked in | |
3169 // verification_mark_bm() is also marked in markBitMap(); flag all | |
3170 // errors by printing corresponding objects. | |
3171 VerifyMarkedClosure vcl(markBitMap()); | |
3172 verification_mark_bm()->iterate(&vcl); | |
3173 assert(!vcl.failed(), "Else verification above should not have succeeded"); | |
3174 } | |
3175 | |
3176 void ConcurrentMarkSweepGeneration::save_marks() { | |
3177 // delegate to CMS space | |
3178 cmsSpace()->save_marks(); | |
3179 for (uint i = 0; i < ParallelGCThreads; i++) { | |
3180 _par_gc_thread_states[i]->promo.startTrackingPromotions(); | |
3181 } | |
3182 } | |
3183 | |
3184 bool ConcurrentMarkSweepGeneration::no_allocs_since_save_marks() { | |
3185 return cmsSpace()->no_allocs_since_save_marks(); | |
3186 } | |
3187 | |
3188 #define CMS_SINCE_SAVE_MARKS_DEFN(OopClosureType, nv_suffix) \ | |
3189 \ | |
3190 void ConcurrentMarkSweepGeneration:: \ | |
3191 oop_since_save_marks_iterate##nv_suffix(OopClosureType* cl) { \ | |
3192 cl->set_generation(this); \ | |
3193 cmsSpace()->oop_since_save_marks_iterate##nv_suffix(cl); \ | |
3194 cl->reset_generation(); \ | |
3195 save_marks(); \ | |
3196 } | |
3197 | |
3198 ALL_SINCE_SAVE_MARKS_CLOSURES(CMS_SINCE_SAVE_MARKS_DEFN) | |
3199 | |
3200 void | |
3201 ConcurrentMarkSweepGeneration::younger_refs_iterate(OopsInGenClosure* cl) { | |
3202 cl->set_generation(this); | |
3203 younger_refs_in_space_iterate(_cmsSpace, cl); | |
3204 cl->reset_generation(); | |
3205 } | |
3206 | |
3207 void | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3208 ConcurrentMarkSweepGeneration::oop_iterate(ExtendedOopClosure* cl) { |
0 | 3209 if (freelistLock()->owned_by_self()) { |
3210 Generation::oop_iterate(cl); | |
3211 } else { | |
3212 MutexLockerEx x(freelistLock(), Mutex::_no_safepoint_check_flag); | |
3213 Generation::oop_iterate(cl); | |
3214 } | |
3215 } | |
3216 | |
3217 void | |
3218 ConcurrentMarkSweepGeneration::object_iterate(ObjectClosure* cl) { | |
3219 if (freelistLock()->owned_by_self()) { | |
3220 Generation::object_iterate(cl); | |
3221 } else { | |
3222 MutexLockerEx x(freelistLock(), Mutex::_no_safepoint_check_flag); | |
3223 Generation::object_iterate(cl); | |
3224 } | |
3225 } | |
3226 | |
3227 void | |
517
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3228 ConcurrentMarkSweepGeneration::safe_object_iterate(ObjectClosure* cl) { |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3229 if (freelistLock()->owned_by_self()) { |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3230 Generation::safe_object_iterate(cl); |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3231 } else { |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3232 MutexLockerEx x(freelistLock(), Mutex::_no_safepoint_check_flag); |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3233 Generation::safe_object_iterate(cl); |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3234 } |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3235 } |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3236 |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3237 void |
0 | 3238 ConcurrentMarkSweepGeneration::post_compact() { |
3239 } | |
3240 | |
3241 void | |
3242 ConcurrentMarkSweepGeneration::prepare_for_verify() { | |
3243 // Fix the linear allocation blocks to look like free blocks. | |
3244 | |
3245 // Locks are normally acquired/released in gc_prologue/gc_epilogue, but those | |
3246 // are not called when the heap is verified during universe initialization and | |
3247 // at vm shutdown. | |
3248 if (freelistLock()->owned_by_self()) { | |
3249 cmsSpace()->prepare_for_verify(); | |
3250 } else { | |
3251 MutexLockerEx fll(freelistLock(), Mutex::_no_safepoint_check_flag); | |
3252 cmsSpace()->prepare_for_verify(); | |
3253 } | |
3254 } | |
3255 | |
3256 void | |
6008 | 3257 ConcurrentMarkSweepGeneration::verify() { |
0 | 3258 // Locks are normally acquired/released in gc_prologue/gc_epilogue, but those |
3259 // are not called when the heap is verified during universe initialization and | |
3260 // at vm shutdown. | |
3261 if (freelistLock()->owned_by_self()) { | |
6008 | 3262 cmsSpace()->verify(); |
0 | 3263 } else { |
3264 MutexLockerEx fll(freelistLock(), Mutex::_no_safepoint_check_flag); | |
6008 | 3265 cmsSpace()->verify(); |
3266 } | |
3267 } | |
3268 | |
3269 void CMSCollector::verify() { | |
3270 _cmsGen->verify(); | |
0 | 3271 } |
3272 | |
3273 #ifndef PRODUCT | |
3274 bool CMSCollector::overflow_list_is_empty() const { | |
3275 assert(_num_par_pushes >= 0, "Inconsistency"); | |
3276 if (_overflow_list == NULL) { | |
3277 assert(_num_par_pushes == 0, "Inconsistency"); | |
3278 } | |
3279 return _overflow_list == NULL; | |
3280 } | |
3281 | |
3282 // The methods verify_work_stacks_empty() and verify_overflow_empty() | |
3283 // merely consolidate assertion checks that appear to occur together frequently. | |
3284 void CMSCollector::verify_work_stacks_empty() const { | |
3285 assert(_markStack.isEmpty(), "Marking stack should be empty"); | |
3286 assert(overflow_list_is_empty(), "Overflow list should be empty"); | |
3287 } | |
3288 | |
3289 void CMSCollector::verify_overflow_empty() const { | |
3290 assert(overflow_list_is_empty(), "Overflow list should be empty"); | |
3291 assert(no_preserved_marks(), "No preserved marks"); | |
3292 } | |
3293 #endif // PRODUCT | |
3294 | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3295 // 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
|
3296 // ensuing concurrent GC cycle. We will collect and |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3297 // unload classes if it's the case that: |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3298 // (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
|
3299 // ExplicitGCInvokesConcurrentAndUnloadsClasses is set, OR |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3300 // (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
|
3301 // (b) old gen is getting really full |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3302 // 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
|
3303 // 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
|
3304 // 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
|
3305 // 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
|
3306 // 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
|
3307 // the property that concurrent_cycles_since_last_unload() |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3308 // 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
|
3309 // _cmsGen->is_too_full() are |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3310 // themselves also monotonic in that sense. See check_monotonicity() |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3311 // below. |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3312 void CMSCollector::update_should_unload_classes() { |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3313 _should_unload_classes = false; |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3314 // Condition 1 above |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3315 if (_full_gc_requested && ExplicitGCInvokesConcurrentAndUnloadsClasses) { |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3316 _should_unload_classes = true; |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3317 } else if (CMSClassUnloadingEnabled) { // Condition 2.a above |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3318 // Disjuncts 2.b.(i,ii,iii) above |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3319 _should_unload_classes = (concurrent_cycles_since_last_unload() >= |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3320 CMSClassUnloadingMaxInterval) |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3321 || _cmsGen->is_too_full(); |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3322 } |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3323 } |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3324 |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3325 bool ConcurrentMarkSweepGeneration::is_too_full() const { |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3326 bool res = should_concurrent_collect(); |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3327 res = res && (occupancy() > (double)CMSIsTooFullPercentage/100.0); |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3328 return res; |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3329 } |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3330 |
0 | 3331 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
|
3332 const bool should_verify = VerifyBeforeGC || VerifyAfterGC || VerifyDuringGC |
0 | 3333 || VerifyBeforeExit; |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3334 const int rso = SharedHeap::SO_AllCodeCache; |
0 | 3335 |
13063
40b8c6bad703
8024954: CMS: CMSClassUnloadingMaxInterval is not implemented correctly. This change is also part of the fix for 8024483.
jmasa
parents:
12316
diff
changeset
|
3336 // 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
|
3337 if (should_unload_classes()) { // Should unload classes this cycle |
0 | 3338 remove_root_scanning_option(rso); // Shrink the root set appropriately |
3339 set_verifying(should_verify); // Set verification state for this cycle | |
3340 return; // Nothing else needs to be done at this time | |
3341 } | |
3342 | |
3343 // Not unloading classes this cycle | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3344 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
|
3345 |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3346 if ((!verifying() || unloaded_classes_last_cycle()) && should_verify) { |
0 | 3347 // Include symbols, strings and code cache elements to prevent their resurrection. |
3348 add_root_scanning_option(rso); | |
3349 set_verifying(true); | |
3350 } else if (verifying() && !should_verify) { | |
3351 // We were verifying, but some verification flags got disabled. | |
3352 set_verifying(false); | |
3353 // Exclude symbols, strings and code cache elements from root scanning to | |
3354 // reduce IM and RM pauses. | |
3355 remove_root_scanning_option(rso); | |
3356 } | |
3357 } | |
3358 | |
3359 | |
3360 #ifndef PRODUCT | |
3361 HeapWord* CMSCollector::block_start(const void* p) const { | |
3362 const HeapWord* addr = (HeapWord*)p; | |
3363 if (_span.contains(p)) { | |
3364 if (_cmsGen->cmsSpace()->is_in_reserved(addr)) { | |
3365 return _cmsGen->cmsSpace()->block_start(p); | |
3366 } | |
3367 } | |
3368 return NULL; | |
3369 } | |
3370 #endif | |
3371 | |
3372 HeapWord* | |
3373 ConcurrentMarkSweepGeneration::expand_and_allocate(size_t word_size, | |
3374 bool tlab, | |
3375 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
|
3376 CMSSynchronousYieldRequest yr; |
0 | 3377 assert(!tlab, "Can't deal with TLAB allocation"); |
3378 MutexLockerEx x(freelistLock(), Mutex::_no_safepoint_check_flag); | |
3379 expand(word_size*HeapWordSize, MinHeapDeltaBytes, | |
3380 CMSExpansionCause::_satisfy_allocation); | |
3381 if (GCExpandToAllocateDelayMillis > 0) { | |
3382 os::sleep(Thread::current(), GCExpandToAllocateDelayMillis, false); | |
3383 } | |
9
173195ff483a
6642634: Test nsk/regression/b6186200 crashed with SIGSEGV
ysr
parents:
7
diff
changeset
|
3384 return have_lock_and_allocate(word_size, tlab); |
0 | 3385 } |
3386 | |
3387 // YSR: All of this generation expansion/shrinking stuff is an exact copy of | |
3388 // OneContigSpaceCardGeneration, which makes me wonder if we should move this | |
3389 // to CardGeneration and share it... | |
271
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
196
diff
changeset
|
3390 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
|
3391 return CardGeneration::expand(bytes, expand_bytes); |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
196
diff
changeset
|
3392 } |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
196
diff
changeset
|
3393 |
0 | 3394 void ConcurrentMarkSweepGeneration::expand(size_t bytes, size_t expand_bytes, |
3395 CMSExpansionCause::Cause cause) | |
3396 { | |
271
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
196
diff
changeset
|
3397 |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
196
diff
changeset
|
3398 bool success = expand(bytes, expand_bytes); |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
196
diff
changeset
|
3399 |
0 | 3400 // remember why we expanded; this information is used |
3401 // by shouldConcurrentCollect() when making decisions on whether to start | |
3402 // a new CMS cycle. | |
3403 if (success) { | |
3404 set_expansion_cause(cause); | |
3405 if (PrintGCDetails && Verbose) { | |
3406 gclog_or_tty->print_cr("Expanded CMS gen for %s", | |
3407 CMSExpansionCause::to_string(cause)); | |
3408 } | |
3409 } | |
3410 } | |
3411 | |
3412 HeapWord* ConcurrentMarkSweepGeneration::expand_and_par_lab_allocate(CMSParGCThreadState* ps, size_t word_sz) { | |
3413 HeapWord* res = NULL; | |
3414 MutexLocker x(ParGCRareEvent_lock); | |
3415 while (true) { | |
3416 // Expansion by some other thread might make alloc OK now: | |
3417 res = ps->lab.alloc(word_sz); | |
3418 if (res != NULL) return res; | |
3419 // If there's not enough expansion space available, give up. | |
3420 if (_virtual_space.uncommitted_size() < (word_sz * HeapWordSize)) { | |
3421 return NULL; | |
3422 } | |
3423 // Otherwise, we try expansion. | |
3424 expand(word_sz*HeapWordSize, MinHeapDeltaBytes, | |
3425 CMSExpansionCause::_allocate_par_lab); | |
3426 // Now go around the loop and try alloc again; | |
3427 // A competing par_promote might beat us to the expansion space, | |
3428 // so we may go around the loop again if promotion fails agaion. | |
3429 if (GCExpandToAllocateDelayMillis > 0) { | |
3430 os::sleep(Thread::current(), GCExpandToAllocateDelayMillis, false); | |
3431 } | |
3432 } | |
3433 } | |
3434 | |
3435 | |
3436 bool ConcurrentMarkSweepGeneration::expand_and_ensure_spooling_space( | |
3437 PromotionInfo* promo) { | |
3438 MutexLocker x(ParGCRareEvent_lock); | |
3439 size_t refill_size_bytes = promo->refillSize() * HeapWordSize; | |
3440 while (true) { | |
3441 // Expansion by some other thread might make alloc OK now: | |
3442 if (promo->ensure_spooling_space()) { | |
3443 assert(promo->has_spooling_space(), | |
3444 "Post-condition of successful ensure_spooling_space()"); | |
3445 return true; | |
3446 } | |
3447 // If there's not enough expansion space available, give up. | |
3448 if (_virtual_space.uncommitted_size() < refill_size_bytes) { | |
3449 return false; | |
3450 } | |
3451 // Otherwise, we try expansion. | |
3452 expand(refill_size_bytes, MinHeapDeltaBytes, | |
3453 CMSExpansionCause::_allocate_par_spooling_space); | |
3454 // Now go around the loop and try alloc again; | |
3455 // A competing allocation might beat us to the expansion space, | |
3456 // so we may go around the loop again if allocation fails again. | |
3457 if (GCExpandToAllocateDelayMillis > 0) { | |
3458 os::sleep(Thread::current(), GCExpandToAllocateDelayMillis, false); | |
3459 } | |
3460 } | |
3461 } | |
3462 | |
3463 | |
9072
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3464 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
|
3465 assert_locked_or_safepoint(ExpandHeap_lock); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3466 // Shrink committed space |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3467 _virtual_space.shrink_by(bytes); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3468 // 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
|
3469 _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
|
3470 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
|
3471 // Shrink the shared block offset array |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3472 _bts->resize(new_word_size); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3473 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
|
3474 // Shrink the card table |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3475 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
|
3476 |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3477 if (Verbose && PrintGC) { |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3478 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
|
3479 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
|
3480 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
|
3481 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
|
3482 } |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3483 } |
0 | 3484 |
3485 void ConcurrentMarkSweepGeneration::shrink(size_t bytes) { | |
3486 assert_locked_or_safepoint(Heap_lock); | |
3487 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
|
3488 // 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
|
3489 // 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
|
3490 if (size > 0 && did_compact()) { |
0 | 3491 shrink_by(size); |
3492 } | |
3493 } | |
3494 | |
3495 bool ConcurrentMarkSweepGeneration::grow_by(size_t bytes) { | |
3496 assert_locked_or_safepoint(Heap_lock); | |
3497 bool result = _virtual_space.expand_by(bytes); | |
3498 if (result) { | |
3499 size_t new_word_size = | |
3500 heap_word_size(_virtual_space.committed_size()); | |
3501 MemRegion mr(_cmsSpace->bottom(), new_word_size); | |
3502 _bts->resize(new_word_size); // resize the block offset shared array | |
3503 Universe::heap()->barrier_set()->resize_covered_region(mr); | |
3504 // Hmmmm... why doesn't CFLS::set_end verify locking? | |
3505 // This is quite ugly; FIX ME XXX | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
3506 _cmsSpace->assert_locked(freelistLock()); |
0 | 3507 _cmsSpace->set_end((HeapWord*)_virtual_space.high()); |
3508 | |
3509 // update the space and generation capacity counters | |
3510 if (UsePerfData) { | |
3511 _space_counters->update_capacity(); | |
3512 _gen_counters->update_all(); | |
3513 } | |
3514 | |
3515 if (Verbose && PrintGC) { | |
3516 size_t new_mem_size = _virtual_space.committed_size(); | |
3517 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
|
3518 gclog_or_tty->print_cr("Expanding %s from " SIZE_FORMAT "K by " SIZE_FORMAT "K to " SIZE_FORMAT "K", |
0 | 3519 name(), old_mem_size/K, bytes/K, new_mem_size/K); |
3520 } | |
3521 } | |
3522 return result; | |
3523 } | |
3524 | |
3525 bool ConcurrentMarkSweepGeneration::grow_to_reserved() { | |
3526 assert_locked_or_safepoint(Heap_lock); | |
3527 bool success = true; | |
3528 const size_t remaining_bytes = _virtual_space.uncommitted_size(); | |
3529 if (remaining_bytes > 0) { | |
3530 success = grow_by(remaining_bytes); | |
3531 DEBUG_ONLY(if (!success) warning("grow to reserved failed");) | |
3532 } | |
3533 return success; | |
3534 } | |
3535 | |
9072
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3536 void ConcurrentMarkSweepGeneration::shrink_free_list_by(size_t bytes) { |
0 | 3537 assert_locked_or_safepoint(Heap_lock); |
3538 assert_lock_strong(freelistLock()); | |
10180
ebded0261dfc
8012111: Remove warning about CMS generation shrinking.
jmasa
parents:
9152
diff
changeset
|
3539 if (PrintGCDetails && Verbose) { |
ebded0261dfc
8012111: Remove warning about CMS generation shrinking.
jmasa
parents:
9152
diff
changeset
|
3540 warning("Shrinking of CMS not yet implemented"); |
ebded0261dfc
8012111: Remove warning about CMS generation shrinking.
jmasa
parents:
9152
diff
changeset
|
3541 } |
0 | 3542 return; |
3543 } | |
3544 | |
3545 | |
3546 // Simple ctor/dtor wrapper for accounting & timer chores around concurrent | |
3547 // phases. | |
3548 class CMSPhaseAccounting: public StackObj { | |
3549 public: | |
3550 CMSPhaseAccounting(CMSCollector *collector, | |
3551 const char *phase, | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
3552 const GCId gc_id, |
0 | 3553 bool print_cr = true); |
3554 ~CMSPhaseAccounting(); | |
3555 | |
3556 private: | |
3557 CMSCollector *_collector; | |
3558 const char *_phase; | |
3559 elapsedTimer _wallclock; | |
3560 bool _print_cr; | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
3561 const GCId _gc_id; |
0 | 3562 |
3563 public: | |
3564 // Not MT-safe; so do not pass around these StackObj's | |
3565 // where they may be accessed by other threads. | |
3566 jlong wallclock_millis() { | |
3567 assert(_wallclock.is_active(), "Wall clock should not stop"); | |
3568 _wallclock.stop(); // to record time | |
3569 jlong ret = _wallclock.milliseconds(); | |
3570 _wallclock.start(); // restart | |
3571 return ret; | |
3572 } | |
3573 }; | |
3574 | |
3575 CMSPhaseAccounting::CMSPhaseAccounting(CMSCollector *collector, | |
3576 const char *phase, | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
3577 const GCId gc_id, |
0 | 3578 bool print_cr) : |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
3579 _collector(collector), _phase(phase), _print_cr(print_cr), _gc_id(gc_id) { |
0 | 3580 |
3581 if (PrintCMSStatistics != 0) { | |
3582 _collector->resetYields(); | |
3583 } | |
8740
62609ffa2fc6
8008684: CMS: concurrent phase start markers should always be printed
tschatzl
parents:
8736
diff
changeset
|
3584 if (PrintGCDetails) { |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
3585 gclog_or_tty->gclog_stamp(_gc_id); |
8740
62609ffa2fc6
8008684: CMS: concurrent phase start markers should always be printed
tschatzl
parents:
8736
diff
changeset
|
3586 gclog_or_tty->print_cr("[%s-concurrent-%s-start]", |
0 | 3587 _collector->cmsGen()->short_name(), _phase); |
3588 } | |
3589 _collector->resetTimer(); | |
3590 _wallclock.start(); | |
3591 _collector->startTimer(); | |
3592 } | |
3593 | |
3594 CMSPhaseAccounting::~CMSPhaseAccounting() { | |
3595 assert(_wallclock.is_active(), "Wall clock should not have stopped"); | |
3596 _collector->stopTimer(); | |
3597 _wallclock.stop(); | |
3598 if (PrintGCDetails) { | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
3599 gclog_or_tty->gclog_stamp(_gc_id); |
0 | 3600 gclog_or_tty->print("[%s-concurrent-%s: %3.3f/%3.3f secs]", |
3601 _collector->cmsGen()->short_name(), | |
3602 _phase, _collector->timerValue(), _wallclock.seconds()); | |
3603 if (_print_cr) { | |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17935
diff
changeset
|
3604 gclog_or_tty->cr(); |
0 | 3605 } |
3606 if (PrintCMSStatistics != 0) { | |
3607 gclog_or_tty->print_cr(" (CMS-concurrent-%s yielded %d times)", _phase, | |
3608 _collector->yields()); | |
3609 } | |
3610 } | |
3611 } | |
3612 | |
3613 // CMS work | |
3614 | |
11975 | 3615 // The common parts of CMSParInitialMarkTask and CMSParRemarkTask. |
3616 class CMSParMarkTask : public AbstractGangTask { | |
3617 protected: | |
3618 CMSCollector* _collector; | |
3619 int _n_workers; | |
3620 CMSParMarkTask(const char* name, CMSCollector* collector, int n_workers) : | |
3621 AbstractGangTask(name), | |
3622 _collector(collector), | |
3623 _n_workers(n_workers) {} | |
3624 // Work method in support of parallel rescan ... of young gen spaces | |
3625 void do_young_space_rescan(uint worker_id, OopsInGenClosure* cl, | |
3626 ContiguousSpace* space, | |
3627 HeapWord** chunk_array, size_t chunk_top); | |
3628 void work_on_young_gen_roots(uint worker_id, OopsInGenClosure* cl); | |
3629 }; | |
3630 | |
3631 // Parallel initial mark task | |
3632 class CMSParInitialMarkTask: public CMSParMarkTask { | |
3633 public: | |
3634 CMSParInitialMarkTask(CMSCollector* collector, int n_workers) : | |
3635 CMSParMarkTask("Scan roots and young gen for initial mark in parallel", | |
3636 collector, n_workers) {} | |
3637 void work(uint worker_id); | |
3638 }; | |
3639 | |
0 | 3640 // Checkpoint the roots into this generation from outside |
3641 // this generation. [Note this initial checkpoint need only | |
3642 // be approximate -- we'll do a catch up phase subsequently.] | |
3643 void CMSCollector::checkpointRootsInitial(bool asynch) { | |
3644 assert(_collectorState == InitialMarking, "Wrong collector state"); | |
3645 check_correct_thread_executing(); | |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
3293
diff
changeset
|
3646 TraceCMSMemoryManagerStats tms(_collectorState,GenCollectedHeap::heap()->gc_cause()); |
2125
7246a374a9f2
6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents:
1994
diff
changeset
|
3647 |
10405 | 3648 save_heap_summary(); |
3649 report_heap_summary(GCWhen::BeforeGC); | |
3650 | |
0 | 3651 ReferenceProcessor* rp = ref_processor(); |
3652 SpecializationStats::clear(); | |
3653 assert(_restart_addr == NULL, "Control point invariant"); | |
3654 if (asynch) { | |
3655 // acquire locks for subsequent manipulations | |
3656 MutexLockerEx x(bitMapLock(), | |
3657 Mutex::_no_safepoint_check_flag); | |
3658 checkpointRootsInitialWork(asynch); | |
3979
4dfb2df418f2
6484982: G1: process references during evacuation pauses
johnc
parents:
3827
diff
changeset
|
3659 // enable ("weak") refs discovery |
4dfb2df418f2
6484982: G1: process references during evacuation pauses
johnc
parents:
3827
diff
changeset
|
3660 rp->enable_discovery(true /*verify_disabled*/, true /*check_no_refs*/); |
0 | 3661 _collectorState = Marking; |
3662 } else { | |
3663 // (Weak) Refs discovery: this is controlled from genCollectedHeap::do_collection | |
3664 // which recognizes if we are a CMS generation, and doesn't try to turn on | |
3665 // discovery; verify that they aren't meddling. | |
3666 assert(!rp->discovery_is_atomic(), | |
3667 "incorrect setting of discovery predicate"); | |
3668 assert(!rp->discovery_enabled(), "genCollectedHeap shouldn't control " | |
3669 "ref discovery for this generation kind"); | |
3670 // already have locks | |
3671 checkpointRootsInitialWork(asynch); | |
3979
4dfb2df418f2
6484982: G1: process references during evacuation pauses
johnc
parents:
3827
diff
changeset
|
3672 // now enable ("weak") refs discovery |
4dfb2df418f2
6484982: G1: process references during evacuation pauses
johnc
parents:
3827
diff
changeset
|
3673 rp->enable_discovery(true /*verify_disabled*/, false /*verify_no_refs*/); |
0 | 3674 _collectorState = Marking; |
3675 } | |
3676 SpecializationStats::print(); | |
3677 } | |
3678 | |
3679 void CMSCollector::checkpointRootsInitialWork(bool asynch) { | |
3680 assert(SafepointSynchronize::is_at_safepoint(), "world should be stopped"); | |
3681 assert(_collectorState == InitialMarking, "just checking"); | |
3682 | |
3683 // If there has not been a GC[n-1] since last GC[n] cycle completed, | |
3684 // precede our marking with a collection of all | |
3685 // younger generations to keep floating garbage to a minimum. | |
3686 // XXX: we won't do this for now -- it's an optimization to be done later. | |
3687 | |
3688 // already have locks | |
3689 assert_lock_strong(bitMapLock()); | |
3690 assert(_markBitMap.isAllClear(), "was reset at end of previous cycle"); | |
3691 | |
3692 // Setup the verification and class unloading state for this | |
3693 // CMS collection cycle. | |
3694 setup_cms_unloading_and_verification_state(); | |
3695 | |
10405 | 3696 NOT_PRODUCT(GCTraceTime t("\ncheckpointRootsInitialWork", |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
3697 PrintGCDetails && Verbose, true, _gc_timer_cm, _gc_tracer_cm->gc_id());) |
0 | 3698 if (UseAdaptiveSizePolicy) { |
3699 size_policy()->checkpoint_roots_initial_begin(); | |
3700 } | |
3701 | |
3702 // Reset all the PLAB chunk arrays if necessary. | |
3703 if (_survivor_plab_array != NULL && !CMSPLABRecordAlways) { | |
3704 reset_survivor_plab_arrays(); | |
3705 } | |
3706 | |
3707 ResourceMark rm; | |
3708 HandleMark hm; | |
3709 | |
994
753cf9794df9
6885169: merge of 4957990 and 6863023 causes conflict on do_nmethods
jrose
parents:
993
diff
changeset
|
3710 MarkRefsIntoClosure notOlder(_span, &_markBitMap); |
0 | 3711 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
3712 | |
3713 verify_work_stacks_empty(); | |
3714 verify_overflow_empty(); | |
3715 | |
3716 gch->ensure_parsability(false); // fill TLABs, but no need to retire them | |
3717 // Update the saved marks which may affect the root scans. | |
3718 gch->save_marks(); | |
3719 | |
3720 // weak reference processing has not started yet. | |
3721 ref_processor()->set_enqueuing_is_done(false); | |
3722 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3723 // Need to remember all newly created CLDs, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3724 // 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
|
3725 ClassLoaderDataGraph::remember_new_clds(true); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3726 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3727 // 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
|
3728 // 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
|
3729 ClassLoaderDataGraph::clear_claimed_marks(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3730 |
11973
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
3731 if (CMSPrintEdenSurvivorChunks) { |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
3732 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
|
3733 } |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
3734 |
0 | 3735 { |
22294
d86b226e331a
Enable derived oop processing by the GC with JVMCI
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
20804
diff
changeset
|
3736 #if defined(COMPILER2) || defined(JVMCI) |
d86b226e331a
Enable derived oop processing by the GC with JVMCI
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
20804
diff
changeset
|
3737 DerivedPointerTableDeactivate dpt_deact; |
d86b226e331a
Enable derived oop processing by the GC with JVMCI
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
20804
diff
changeset
|
3738 #endif |
11975 | 3739 if (CMSParallelInitialMarkEnabled && CollectedHeap::use_parallel_gc_threads()) { |
3740 // The parallel version. | |
3741 FlexibleWorkGang* workers = gch->workers(); | |
3742 assert(workers != NULL, "Need parallel worker threads."); | |
3743 int n_workers = workers->active_workers(); | |
3744 CMSParInitialMarkTask tsk(this, n_workers); | |
3745 gch->set_par_threads(n_workers); | |
3746 initialize_sequential_subtasks_for_young_gen_rescan(n_workers); | |
3747 if (n_workers > 1) { | |
3748 GenCollectedHeap::StrongRootsScope srs(gch); | |
3749 workers->run_task(&tsk); | |
3750 } else { | |
3751 GenCollectedHeap::StrongRootsScope srs(gch); | |
3752 tsk.work(0); | |
3753 } | |
3754 gch->set_par_threads(0); | |
3755 } else { | |
3756 // The serial version. | |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3757 CLDToOopClosure cld_closure(¬Older, true); |
11975 | 3758 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
|
3759 gch->gen_process_roots(_cmsGen->level(), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3760 true, // younger gens are roots |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3761 true, // activate StrongRootsScope |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3762 SharedHeap::ScanningOption(roots_scanning_options()), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3763 should_unload_classes(), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3764 ¬Older, |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3765 NULL, |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3766 &cld_closure); |
11975 | 3767 } |
0 | 3768 } |
3769 | |
3770 // Clear mod-union table; it will be dirtied in the prologue of | |
3771 // CMS generation per each younger generation collection. | |
3772 | |
3773 assert(_modUnionTable.isAllClear(), | |
3774 "Was cleared in most recent final checkpoint phase" | |
3775 " or no bits are set in the gc_prologue before the start of the next " | |
3776 "subsequent marking phase."); | |
3777 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3778 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
|
3779 |
0 | 3780 // Save the end of the used_region of the constituent generations |
3781 // to be used to limit the extent of sweep in each generation. | |
3782 save_sweep_limits(); | |
3783 if (UseAdaptiveSizePolicy) { | |
3784 size_policy()->checkpoint_roots_initial_end(gch->gc_cause()); | |
3785 } | |
3786 verify_overflow_empty(); | |
3787 } | |
3788 | |
3789 bool CMSCollector::markFromRoots(bool asynch) { | |
3790 // we might be tempted to assert that: | |
3791 // assert(asynch == !SafepointSynchronize::is_at_safepoint(), | |
3792 // "inconsistent argument?"); | |
3793 // However that wouldn't be right, because it's possible that | |
3794 // a safepoint is indeed in progress as a younger generation | |
3795 // stop-the-world GC happens even as we mark in this generation. | |
3796 assert(_collectorState == Marking, "inconsistent state?"); | |
3797 check_correct_thread_executing(); | |
3798 verify_overflow_empty(); | |
3799 | |
3800 bool res; | |
3801 if (asynch) { | |
3802 | |
3803 // Start the timers for adaptive size policy for the concurrent phases | |
3804 // Do it here so that the foreground MS can use the concurrent | |
3805 // timer since a foreground MS might has the sweep done concurrently | |
3806 // or STW. | |
3807 if (UseAdaptiveSizePolicy) { | |
3808 size_policy()->concurrent_marking_begin(); | |
3809 } | |
3810 | |
3811 // Weak ref discovery note: We may be discovering weak | |
3812 // refs in this generation concurrent (but interleaved) with | |
3813 // weak ref discovery by a younger generation collector. | |
3814 | |
3815 CMSTokenSyncWithLocks ts(true, bitMapLock()); | |
3816 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
|
3817 CMSPhaseAccounting pa(this, "mark", _gc_tracer_cm->gc_id(), !PrintGCDetails); |
0 | 3818 res = markFromRootsWork(asynch); |
3819 if (res) { | |
3820 _collectorState = Precleaning; | |
3821 } else { // We failed and a foreground collection wants to take over | |
3822 assert(_foregroundGCIsActive, "internal state inconsistency"); | |
3823 assert(_restart_addr == NULL, "foreground will restart from scratch"); | |
3824 if (PrintGCDetails) { | |
3825 gclog_or_tty->print_cr("bailing out to foreground collection"); | |
3826 } | |
3827 } | |
3828 if (UseAdaptiveSizePolicy) { | |
3829 size_policy()->concurrent_marking_end(); | |
3830 } | |
3831 } else { | |
3832 assert(SafepointSynchronize::is_at_safepoint(), | |
3833 "inconsistent with asynch == false"); | |
3834 if (UseAdaptiveSizePolicy) { | |
3835 size_policy()->ms_collection_marking_begin(); | |
3836 } | |
3837 // already have locks | |
3838 res = markFromRootsWork(asynch); | |
3839 _collectorState = FinalMarking; | |
3840 if (UseAdaptiveSizePolicy) { | |
3841 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
3842 size_policy()->ms_collection_marking_end(gch->gc_cause()); | |
3843 } | |
3844 } | |
3845 verify_overflow_empty(); | |
3846 return res; | |
3847 } | |
3848 | |
3849 bool CMSCollector::markFromRootsWork(bool asynch) { | |
3850 // iterate over marked bits in bit map, doing a full scan and mark | |
3851 // from these roots using the following algorithm: | |
3852 // . if oop is to the right of the current scan pointer, | |
3853 // mark corresponding bit (we'll process it later) | |
3854 // . else (oop is to left of current scan pointer) | |
3855 // push oop on marking stack | |
3856 // . drain the marking stack | |
3857 | |
3858 // Note that when we do a marking step we need to hold the | |
3859 // bit map lock -- recall that direct allocation (by mutators) | |
3860 // and promotion (by younger generation collectors) is also | |
3861 // marking the bit map. [the so-called allocate live policy.] | |
3862 // Because the implementation of bit map marking is not | |
3863 // robust wrt simultaneous marking of bits in the same word, | |
3864 // we need to make sure that there is no such interference | |
3865 // between concurrent such updates. | |
3866 | |
3867 // already have locks | |
3868 assert_lock_strong(bitMapLock()); | |
3869 | |
3870 verify_work_stacks_empty(); | |
3871 verify_overflow_empty(); | |
3872 bool result = false; | |
1284 | 3873 if (CMSConcurrentMTEnabled && ConcGCThreads > 0) { |
0 | 3874 result = do_marking_mt(asynch); |
3875 } else { | |
3876 result = do_marking_st(asynch); | |
3877 } | |
3878 return result; | |
3879 } | |
3880 | |
3881 // Forward decl | |
3882 class CMSConcMarkingTask; | |
3883 | |
3884 class CMSConcMarkingTerminator: public ParallelTaskTerminator { | |
3885 CMSCollector* _collector; | |
3886 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
|
3887 public: |
0 | 3888 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
|
3889 |
0 | 3890 // "n_threads" is the number of threads to be terminated. |
3891 // "queue_set" is a set of work queues of other threads. | |
3892 // "collector" is the CMS collector associated with this task terminator. | |
3893 // "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
|
3894 CMSConcMarkingTerminator(int n_threads, TaskQueueSetSuper* queue_set, CMSCollector* collector) : |
0 | 3895 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
|
3896 _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
|
3897 |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3898 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
|
3899 _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
|
3900 } |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3901 }; |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3902 |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3903 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
|
3904 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
|
3905 public: |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3906 bool should_exit_termination(); |
0 | 3907 void set_task(CMSConcMarkingTask* task) { |
3908 _task = task; | |
3909 } | |
3910 }; | |
3911 | |
3912 // MT Concurrent Marking Task | |
3913 class CMSConcMarkingTask: public YieldingFlexibleGangTask { | |
3914 CMSCollector* _collector; | |
3915 int _n_workers; // requested/desired # workers | |
3916 bool _asynch; | |
3917 bool _result; | |
3918 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
|
3919 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
|
3920 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
|
3921 char _pad_back[64]; |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
3922 HeapWord* _restart_addr; |
0 | 3923 |
3924 // Exposed here for yielding support | |
3925 Mutex* const _bit_map_lock; | |
3926 | |
3927 // The per thread work queues, available here for stealing | |
3928 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
|
3929 |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3930 // Termination (and yielding) support |
0 | 3931 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
|
3932 CMSConcMarkingTerminatorTerminator _term_term; |
0 | 3933 |
3934 public: | |
3935 CMSConcMarkingTask(CMSCollector* collector, | |
3936 CompactibleFreeListSpace* cms_space, | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
3937 bool asynch, |
0 | 3938 YieldingFlexibleWorkGang* workers, |
3939 OopTaskQueueSet* task_queues): | |
3940 YieldingFlexibleGangTask("Concurrent marking done multi-threaded"), | |
3941 _collector(collector), | |
3942 _cms_space(cms_space), | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
3943 _asynch(asynch), _n_workers(0), _result(true), |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
3944 _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
|
3945 _term(_n_workers, task_queues, _collector), |
0 | 3946 _bit_map_lock(collector->bitMapLock()) |
3947 { | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
3948 _requested_size = _n_workers; |
0 | 3949 _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
|
3950 _term_term.set_task(this); |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
3951 _restart_addr = _global_finger = _cms_space->bottom(); |
0 | 3952 } |
3953 | |
3954 | |
3955 OopTaskQueueSet* task_queues() { return _task_queues; } | |
3956 | |
3957 OopTaskQueue* work_queue(int i) { return task_queues()->queue(i); } | |
3958 | |
3959 HeapWord** global_finger_addr() { return &_global_finger; } | |
3960 | |
3961 CMSConcMarkingTerminator* terminator() { return &_term; } | |
3962 | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
3963 virtual void set_for_termination(int active_workers) { |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
3964 terminator()->reset_for_reuse(active_workers); |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
3965 } |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
3966 |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
3967 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
|
3968 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
|
3969 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
|
3970 && !_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
|
3971 && _asynch; |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3972 } |
0 | 3973 |
3974 virtual void coordinator_yield(); // stuff done by coordinator | |
3975 bool result() { return _result; } | |
3976 | |
3977 void reset(HeapWord* ra) { | |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
3978 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
|
3979 _restart_addr = _global_finger = ra; |
0 | 3980 _term.reset_for_reuse(); |
3981 } | |
3982 | |
3983 static bool get_work_from_overflow_stack(CMSMarkStack* ovflw_stk, | |
3984 OopTaskQueue* work_q); | |
3985 | |
3986 private: | |
3987 void do_scan_and_mark(int i, CompactibleFreeListSpace* sp); | |
3988 void do_work_steal(int i); | |
3989 void bump_global_finger(HeapWord* f); | |
3990 }; | |
3991 | |
1837
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3992 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
|
3993 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
|
3994 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
|
3995 // 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
|
3996 // 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
|
3997 // 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
|
3998 // 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
|
3999 } |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
4000 |
0 | 4001 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
|
4002 if (_task->should_yield()) { |
0 | 4003 _task->yield(); |
4004 } else { | |
4005 ParallelTaskTerminator::yield(); | |
4006 } | |
4007 } | |
4008 | |
4009 //////////////////////////////////////////////////////////////// | |
4010 // Concurrent Marking Algorithm Sketch | |
4011 //////////////////////////////////////////////////////////////// | |
4012 // Until all tasks exhausted (both spaces): | |
4013 // -- claim next available chunk | |
4014 // -- bump global finger via CAS | |
4015 // -- find first object that starts in this chunk | |
4016 // and start scanning bitmap from that position | |
4017 // -- scan marked objects for oops | |
4018 // -- CAS-mark target, and if successful: | |
4019 // . if target oop is above global finger (volatile read) | |
4020 // nothing to do | |
4021 // . if target oop is in chunk and above local finger | |
4022 // then nothing to do | |
4023 // . else push on work-queue | |
4024 // -- Deal with possible overflow issues: | |
4025 // . local work-queue overflow causes stuff to be pushed on | |
4026 // global (common) overflow queue | |
4027 // . always first empty local work queue | |
4028 // . then get a batch of oops from global work queue if any | |
4029 // . then do work stealing | |
4030 // -- When all tasks claimed (both spaces) | |
4031 // and local work queue empty, | |
4032 // then in a loop do: | |
4033 // . check global overflow stack; steal a batch of oops and trace | |
4034 // . try to steal from other threads oif GOS is empty | |
4035 // . if neither is available, offer termination | |
4036 // -- Terminate and return result | |
4037 // | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
4038 void CMSConcMarkingTask::work(uint worker_id) { |
0 | 4039 elapsedTimer _timer; |
4040 ResourceMark rm; | |
4041 HandleMark hm; | |
4042 | |
4043 DEBUG_ONLY(_collector->verify_overflow_empty();) | |
4044 | |
4045 // 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
|
4046 assert(work_queue(worker_id)->size() == 0, "Expected to be empty"); |
0 | 4047 // Scan the bitmap covering _cms_space, tracing through grey objects. |
4048 _timer.start(); | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
4049 do_scan_and_mark(worker_id, _cms_space); |
0 | 4050 _timer.stop(); |
4051 if (PrintCMSStatistics != 0) { | |
4052 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
|
4053 worker_id, _timer.seconds()); |
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
4054 // XXX: need xxx/xxx type of notation, two timers |
0 | 4055 } |
4056 | |
4057 // ... do work stealing | |
4058 _timer.reset(); | |
4059 _timer.start(); | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
4060 do_work_steal(worker_id); |
0 | 4061 _timer.stop(); |
4062 if (PrintCMSStatistics != 0) { | |
4063 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
|
4064 worker_id, _timer.seconds()); |
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
4065 // XXX: need xxx/xxx type of notation, two timers |
0 | 4066 } |
4067 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
|
4068 assert(work_queue(worker_id)->size() == 0, "Should have been emptied"); |
0 | 4069 // Note that under the current task protocol, the |
4070 // following assertion is true even of the spaces | |
4071 // expanded since the completion of the concurrent | |
4072 // marking. XXX This will likely change under a strict | |
4073 // ABORT semantics. | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4074 // After perm removal the comparison was changed to |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4075 // 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
|
4076 // Before perm removal the highest address sweep would |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4077 // 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
|
4078 // end of the tenured gen. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4079 assert(_global_finger >= _cms_space->end(), |
0 | 4080 "All tasks have been completed"); |
4081 DEBUG_ONLY(_collector->verify_overflow_empty();) | |
4082 } | |
4083 | |
4084 void CMSConcMarkingTask::bump_global_finger(HeapWord* f) { | |
4085 HeapWord* read = _global_finger; | |
4086 HeapWord* cur = read; | |
4087 while (f > read) { | |
4088 cur = read; | |
4089 read = (HeapWord*) Atomic::cmpxchg_ptr(f, &_global_finger, cur); | |
4090 if (cur == read) { | |
4091 // our cas succeeded | |
4092 assert(_global_finger >= f, "protocol consistency"); | |
4093 break; | |
4094 } | |
4095 } | |
4096 } | |
4097 | |
4098 // This is really inefficient, and should be redone by | |
4099 // using (not yet available) block-read and -write interfaces to the | |
4100 // stack and the work_queue. XXX FIX ME !!! | |
4101 bool CMSConcMarkingTask::get_work_from_overflow_stack(CMSMarkStack* ovflw_stk, | |
4102 OopTaskQueue* work_q) { | |
4103 // Fast lock-free check | |
4104 if (ovflw_stk->length() == 0) { | |
4105 return false; | |
4106 } | |
4107 assert(work_q->size() == 0, "Shouldn't steal"); | |
4108 MutexLockerEx ml(ovflw_stk->par_lock(), | |
4109 Mutex::_no_safepoint_check_flag); | |
4110 // 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
|
4111 size_t num = MIN2((size_t)(work_q->max_elems() - work_q->size())/4, |
0 | 4112 (size_t)ParGCDesiredObjsFromOverflowList); |
4113 num = MIN2(num, ovflw_stk->length()); | |
4114 for (int i = (int) num; i > 0; i--) { | |
4115 oop cur = ovflw_stk->pop(); | |
4116 assert(cur != NULL, "Counted wrong?"); | |
4117 work_q->push(cur); | |
4118 } | |
4119 return num > 0; | |
4120 } | |
4121 | |
4122 void CMSConcMarkingTask::do_scan_and_mark(int i, CompactibleFreeListSpace* sp) { | |
4123 SequentialSubTasksDone* pst = sp->conc_par_seq_tasks(); | |
4124 int n_tasks = pst->n_tasks(); | |
4125 // We allow that there may be no tasks to do here because | |
4126 // we are restarting after a stack overflow. | |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4127 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
|
4128 uint nth_task = 0; |
0 | 4129 |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4130 HeapWord* aligned_start = sp->bottom(); |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4131 if (sp->used_region().contains(_restart_addr)) { |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4132 // 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
|
4133 // for this space. |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4134 aligned_start = |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4135 (HeapWord*)align_size_down((uintptr_t)_restart_addr, |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4136 CardTableModRefBS::card_size); |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4137 } |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4138 |
0 | 4139 size_t chunk_size = sp->marking_task_size(); |
4140 while (!pst->is_task_claimed(/* reference */ nth_task)) { | |
4141 // Having claimed the nth task in this space, | |
4142 // compute the chunk that it corresponds to: | |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4143 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
|
4144 aligned_start + (nth_task+1)*chunk_size); |
0 | 4145 // Try and bump the global finger via a CAS; |
4146 // note that we need to do the global finger bump | |
4147 // _before_ taking the intersection below, because | |
4148 // the task corresponding to that region will be | |
4149 // deemed done even if the used_region() expands | |
4150 // because of allocation -- as it almost certainly will | |
4151 // during start-up while the threads yield in the | |
4152 // closure below. | |
4153 HeapWord* finger = span.end(); | |
4154 bump_global_finger(finger); // atomically | |
4155 // There are null tasks here corresponding to chunks | |
4156 // beyond the "top" address of the space. | |
4157 span = span.intersection(sp->used_region()); | |
4158 if (!span.is_empty()) { // Non-null task | |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4159 HeapWord* prev_obj; |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4160 assert(!span.contains(_restart_addr) || nth_task == 0, |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4161 "Inconsistency"); |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4162 if (nth_task == 0) { |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4163 // 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
|
4164 if (span.contains(_restart_addr)) { |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4165 // 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
|
4166 // we might additionally skip a chunk prefix. |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4167 prev_obj = _restart_addr; |
0 | 4168 } else { |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4169 prev_obj = span.start(); |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4170 } |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4171 } else { |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4172 // We want to skip the first object because |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4173 // 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
|
4174 // that _starts_ in this span; a fortiori, any |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4175 // object starting in an earlier span is scanned |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4176 // as part of an earlier claimed task. |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4177 // 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
|
4178 // 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
|
4179 prev_obj = sp->block_start_careful(span.start()); |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4180 // 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
|
4181 // Printezis bits to avoid waiting for allocated |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4182 // objects to become initialized/parsable. |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4183 while (prev_obj < span.start()) { |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4184 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
|
4185 if (sz > 0) { |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4186 prev_obj += sz; |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4187 } else { |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4188 // 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
|
4189 // scanning, but that appears unavoidable, short of |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4190 // locking the free list locks; see bug 6324141. |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4191 break; |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4192 } |
0 | 4193 } |
4194 } | |
4195 if (prev_obj < span.end()) { | |
4196 MemRegion my_span = MemRegion(prev_obj, span.end()); | |
4197 // Do the marking work within a non-empty span -- | |
4198 // the last argument to the constructor indicates whether the | |
4199 // iteration should be incremental with periodic yields. | |
4200 Par_MarkFromRootsClosure cl(this, _collector, my_span, | |
4201 &_collector->_markBitMap, | |
4202 work_queue(i), | |
4203 &_collector->_markStack, | |
4204 _asynch); | |
4205 _collector->_markBitMap.iterate(&cl, my_span.start(), my_span.end()); | |
4206 } // else nothing to do for this task | |
4207 } // else nothing to do for this task | |
4208 } | |
4209 // We'd be tempted to assert here that since there are no | |
4210 // more tasks left to claim in this space, the global_finger | |
4211 // must exceed space->top() and a fortiori space->end(). However, | |
4212 // that would not quite be correct because the bumping of | |
4213 // global_finger occurs strictly after the claiming of a task, | |
4214 // so by the time we reach here the global finger may not yet | |
4215 // have been bumped up by the thread that claimed the last | |
4216 // task. | |
4217 pst->all_tasks_completed(); | |
4218 } | |
4219 | |
20268
4c1b88a53c74
8046670: Make CMS metadata aware closures applicable for other collectors
stefank
parents:
20264
diff
changeset
|
4220 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
|
4221 private: |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4222 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
|
4223 CMSConcMarkingTask* _task; |
0 | 4224 MemRegion _span; |
4225 CMSBitMap* _bit_map; | |
4226 CMSMarkStack* _overflow_stack; | |
4227 OopTaskQueue* _work_queue; | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
4228 protected: |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
4229 DO_OOP_WORK_DEFN |
0 | 4230 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
|
4231 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
|
4232 CMSBitMap* bit_map, CMSMarkStack* overflow_stack): |
20268
4c1b88a53c74
8046670: Make CMS metadata aware closures applicable for other collectors
stefank
parents:
20264
diff
changeset
|
4233 MetadataAwareOopClosure(collector->ref_processor()), |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4234 _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
|
4235 _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
|
4236 _span(collector->_span), |
0 | 4237 _work_queue(work_queue), |
4238 _bit_map(bit_map), | |
935 | 4239 _overflow_stack(overflow_stack) |
4240 { } | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
4241 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
|
4242 virtual void do_oop(narrowOop* p); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4243 |
0 | 4244 void trim_queue(size_t max); |
4245 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
|
4246 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
|
4247 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
|
4248 _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
|
4249 } |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
4250 } |
0 | 4251 }; |
4252 | |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4253 // Grey object scanning during work stealing phase -- |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4254 // the salient assumption here is that any references |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4255 // 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
|
4256 // 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
|
4257 // 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
|
4258 // 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
|
4259 void Par_ConcMarkingClosure::do_oop(oop obj) { |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4260 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
|
4261 HeapWord* addr = (HeapWord*)obj; |
0 | 4262 // Check if oop points into the CMS generation |
4263 // and is not marked | |
4264 if (_span.contains(addr) && !_bit_map->isMarked(addr)) { | |
4265 // a white object ... | |
4266 // If we manage to "claim" the object, by being the | |
4267 // first thread to mark it, then we push it on our | |
4268 // marking stack | |
4269 if (_bit_map->par_mark(addr)) { // ... now grey | |
4270 // push on work queue (grey set) | |
4271 bool simulate_overflow = false; | |
4272 NOT_PRODUCT( | |
4273 if (CMSMarkStackOverflowALot && | |
4274 _collector->simulate_overflow()) { | |
4275 // simulate a stack overflow | |
4276 simulate_overflow = true; | |
4277 } | |
4278 ) | |
4279 if (simulate_overflow || | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
4280 !(_work_queue->push(obj) || _overflow_stack->par_push(obj))) { |
0 | 4281 // stack overflow |
4282 if (PrintCMSStatistics != 0) { | |
4283 gclog_or_tty->print_cr("CMS marking stack overflow (benign) at " | |
4284 SIZE_FORMAT, _overflow_stack->capacity()); | |
4285 } | |
4286 // We cannot assert that the overflow stack is full because | |
4287 // it may have been emptied since. | |
4288 assert(simulate_overflow || | |
4289 _work_queue->size() == _work_queue->max_elems(), | |
4290 "Else push should have succeeded"); | |
4291 handle_stack_overflow(addr); | |
4292 } | |
4293 } // 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
|
4294 do_yield_check(); |
0 | 4295 } |
4296 } | |
4297 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
4298 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
|
4299 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
|
4300 |
0 | 4301 void Par_ConcMarkingClosure::trim_queue(size_t max) { |
4302 while (_work_queue->size() > max) { | |
4303 oop new_oop; | |
4304 if (_work_queue->pop_local(new_oop)) { | |
4305 assert(new_oop->is_oop(), "Should be an oop"); | |
4306 assert(_bit_map->isMarked((HeapWord*)new_oop), "Grey object"); | |
4307 assert(_span.contains((HeapWord*)new_oop), "Not in span"); | |
4308 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
|
4309 do_yield_check(); |
0 | 4310 } |
4311 } | |
4312 } | |
4313 | |
4314 // Upon stack overflow, we discard (part of) the stack, | |
4315 // remembering the least address amongst those discarded | |
4316 // in CMSCollector's _restart_address. | |
4317 void Par_ConcMarkingClosure::handle_stack_overflow(HeapWord* lost) { | |
4318 // 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
|
4319 // workers from interfering with the work done below. |
0 | 4320 MutexLockerEx ml(_overflow_stack->par_lock(), |
4321 Mutex::_no_safepoint_check_flag); | |
4322 // Remember the least grey address discarded | |
4323 HeapWord* ra = (HeapWord*)_overflow_stack->least_value(lost); | |
4324 _collector->lower_restart_addr(ra); | |
4325 _overflow_stack->reset(); // discard stack contents | |
4326 _overflow_stack->expand(); // expand the stack if possible | |
4327 } | |
4328 | |
4329 | |
4330 void CMSConcMarkingTask::do_work_steal(int i) { | |
4331 OopTaskQueue* work_q = work_queue(i); | |
4332 oop obj_to_scan; | |
4333 CMSBitMap* bm = &(_collector->_markBitMap); | |
4334 CMSMarkStack* ovflw = &(_collector->_markStack); | |
4335 int* seed = _collector->hash_seed(i); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4336 Par_ConcMarkingClosure cl(_collector, this, work_q, bm, ovflw); |
0 | 4337 while (true) { |
4338 cl.trim_queue(0); | |
4339 assert(work_q->size() == 0, "Should have been emptied above"); | |
4340 if (get_work_from_overflow_stack(ovflw, work_q)) { | |
4341 // Can't assert below because the work obtained from the | |
4342 // overflow stack may already have been stolen from us. | |
4343 // assert(work_q->size() > 0, "Work from overflow stack"); | |
4344 continue; | |
4345 } else if (task_queues()->steal(i, seed, /* reference */ obj_to_scan)) { | |
4346 assert(obj_to_scan->is_oop(), "Should be an oop"); | |
4347 assert(bm->isMarked((HeapWord*)obj_to_scan), "Grey object"); | |
4348 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
|
4349 } else if (terminator()->offer_termination(&_term_term)) { |
0 | 4350 assert(work_q->size() == 0, "Impossible!"); |
4351 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
|
4352 } 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
|
4353 yield(); |
0 | 4354 } |
4355 } | |
4356 } | |
4357 | |
4358 // This is run by the CMS (coordinator) thread. | |
4359 void CMSConcMarkingTask::coordinator_yield() { | |
4360 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
4361 "CMS thread should hold CMS token"); | |
4362 // First give up the locks, then yield, then re-lock | |
4363 // We should probably use a constructor/destructor idiom to | |
4364 // do this unlock/lock or modify the MutexUnlocker class to | |
4365 // serve our purpose. XXX | |
4366 assert_lock_strong(_bit_map_lock); | |
4367 _bit_map_lock->unlock(); | |
4368 ConcurrentMarkSweepThread::desynchronize(true); | |
4369 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
4370 _collector->stopTimer(); | |
4371 if (PrintCMSStatistics != 0) { | |
4372 _collector->incrementYields(); | |
4373 } | |
4374 _collector->icms_wait(); | |
4375 | |
4376 // It is possible for whichever thread initiated the yield request | |
4377 // not to get a chance to wake up and take the bitmap lock between | |
4378 // this thread releasing it and reacquiring it. So, while the | |
4379 // should_yield() flag is on, let's sleep for a bit to give the | |
4380 // other thread a chance to wake up. The limit imposed on the number | |
4381 // of iterations is defensive, to avoid any unforseen circumstances | |
4382 // putting us into an infinite loop. Since it's always been this | |
4383 // (coordinator_yield()) method that was observed to cause the | |
4384 // problem, we are using a parameter (CMSCoordinatorYieldSleepCount) | |
4385 // which is by default non-zero. For the other seven methods that | |
4386 // also perform the yield operation, as are using a different | |
4387 // parameter (CMSYieldSleepCount) which is by default zero. This way we | |
4388 // can enable the sleeping for those methods too, if necessary. | |
4389 // See 6442774. | |
4390 // | |
4391 // We really need to reconsider the synchronization between the GC | |
4392 // thread and the yield-requesting threads in the future and we | |
4393 // should really use wait/notify, which is the recommended | |
4394 // way of doing this type of interaction. Additionally, we should | |
4395 // consolidate the eight methods that do the yield operation and they | |
4396 // are almost identical into one for better maintenability and | |
4397 // readability. See 6445193. | |
4398 // | |
4399 // Tony 2006.06.29 | |
4400 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
|
4401 ConcurrentMarkSweepThread::should_yield() && |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
4402 !CMSCollector::foregroundGCIsActive(); ++i) { |
0 | 4403 os::sleep(Thread::current(), 1, false); |
4404 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
4405 } | |
4406 | |
4407 ConcurrentMarkSweepThread::synchronize(true); | |
4408 _bit_map_lock->lock_without_safepoint_check(); | |
4409 _collector->startTimer(); | |
4410 } | |
4411 | |
4412 bool CMSCollector::do_marking_mt(bool asynch) { | |
1284 | 4413 assert(ConcGCThreads > 0 && conc_workers() != NULL, "precondition"); |
4095
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
4414 int num_workers = AdaptiveSizePolicy::calc_active_conc_workers( |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
4415 conc_workers()->total_workers(), |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
4416 conc_workers()->active_workers(), |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
4417 Threads::number_of_non_daemon_threads()); |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
4418 conc_workers()->set_active_workers(num_workers); |
0 | 4419 |
4420 CompactibleFreeListSpace* cms_space = _cmsGen->cmsSpace(); | |
4421 | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
4422 CMSConcMarkingTask tsk(this, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
4423 cms_space, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
4424 asynch, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
4425 conc_workers(), |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
4426 task_queues()); |
0 | 4427 |
4428 // Since the actual number of workers we get may be different | |
4429 // from the number we requested above, do we need to do anything different | |
4430 // below? In particular, may be we need to subclass the SequantialSubTasksDone | |
4431 // class?? XXX | |
4432 cms_space ->initialize_sequential_subtasks_for_marking(num_workers); | |
4433 | |
4434 // Refs discovery is already non-atomic. | |
4435 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
|
4436 assert(ref_processor()->discovery_is_mt(), "Discovery should be MT"); |
0 | 4437 conc_workers()->start_task(&tsk); |
4438 while (tsk.yielded()) { | |
4439 tsk.coordinator_yield(); | |
4440 conc_workers()->continue_task(&tsk); | |
4441 } | |
4442 // If the task was aborted, _restart_addr will be non-NULL | |
4443 assert(tsk.completed() || _restart_addr != NULL, "Inconsistency"); | |
4444 while (_restart_addr != NULL) { | |
4445 // XXX For now we do not make use of ABORTED state and have not | |
4446 // yet implemented the right abort semantics (even in the original | |
4447 // single-threaded CMS case). That needs some more investigation | |
4448 // and is deferred for now; see CR# TBF. 07252005YSR. XXX | |
4449 assert(!CMSAbortSemantics || tsk.aborted(), "Inconsistency"); | |
4450 // If _restart_addr is non-NULL, a marking stack overflow | |
605 | 4451 // occurred; we need to do a fresh marking iteration from the |
0 | 4452 // indicated restart address. |
4453 if (_foregroundGCIsActive && asynch) { | |
4454 // We may be running into repeated stack overflows, having | |
4455 // reached the limit of the stack size, while making very | |
4456 // slow forward progress. It may be best to bail out and | |
4457 // let the foreground collector do its job. | |
4458 // Clear _restart_addr, so that foreground GC | |
4459 // works from scratch. This avoids the headache of | |
4460 // a "rescan" which would otherwise be needed because | |
4461 // of the dirty mod union table & card table. | |
4462 _restart_addr = NULL; | |
4463 return false; | |
4464 } | |
4465 // Adjust the task to restart from _restart_addr | |
4466 tsk.reset(_restart_addr); | |
4467 cms_space ->initialize_sequential_subtasks_for_marking(num_workers, | |
4468 _restart_addr); | |
4469 _restart_addr = NULL; | |
4470 // Get the workers going again | |
4471 conc_workers()->start_task(&tsk); | |
4472 while (tsk.yielded()) { | |
4473 tsk.coordinator_yield(); | |
4474 conc_workers()->continue_task(&tsk); | |
4475 } | |
4476 } | |
4477 assert(tsk.completed(), "Inconsistency"); | |
4478 assert(tsk.result() == true, "Inconsistency"); | |
4479 return true; | |
4480 } | |
4481 | |
4482 bool CMSCollector::do_marking_st(bool asynch) { | |
4483 ResourceMark rm; | |
4484 HandleMark hm; | |
4485 | |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
4486 // Temporarily make refs discovery single threaded (non-MT) |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
4487 ReferenceProcessorMTDiscoveryMutator rp_mut_discovery(ref_processor(), false); |
0 | 4488 MarkFromRootsClosure markFromRootsClosure(this, _span, &_markBitMap, |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4489 &_markStack, CMSYield && asynch); |
0 | 4490 // the last argument to iterate indicates whether the iteration |
4491 // should be incremental with periodic yields. | |
4492 _markBitMap.iterate(&markFromRootsClosure); | |
4493 // If _restart_addr is non-NULL, a marking stack overflow | |
605 | 4494 // occurred; we need to do a fresh iteration from the |
0 | 4495 // indicated restart address. |
4496 while (_restart_addr != NULL) { | |
4497 if (_foregroundGCIsActive && asynch) { | |
4498 // We may be running into repeated stack overflows, having | |
4499 // reached the limit of the stack size, while making very | |
4500 // slow forward progress. It may be best to bail out and | |
4501 // let the foreground collector do its job. | |
4502 // Clear _restart_addr, so that foreground GC | |
4503 // works from scratch. This avoids the headache of | |
4504 // a "rescan" which would otherwise be needed because | |
4505 // of the dirty mod union table & card table. | |
4506 _restart_addr = NULL; | |
4507 return false; // indicating failure to complete marking | |
4508 } | |
4509 // Deal with stack overflow: | |
4510 // we restart marking from _restart_addr | |
4511 HeapWord* ra = _restart_addr; | |
4512 markFromRootsClosure.reset(ra); | |
4513 _restart_addr = NULL; | |
4514 _markBitMap.iterate(&markFromRootsClosure, ra, _span.end()); | |
4515 } | |
4516 return true; | |
4517 } | |
4518 | |
4519 void CMSCollector::preclean() { | |
4520 check_correct_thread_executing(); | |
4521 assert(Thread::current()->is_ConcurrentGC_thread(), "Wrong thread"); | |
4522 verify_work_stacks_empty(); | |
4523 verify_overflow_empty(); | |
4524 _abort_preclean = false; | |
4525 if (CMSPrecleaningEnabled) { | |
11973
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
4526 if (!CMSEdenChunksRecordAlways) { |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
4527 _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
|
4528 } |
0 | 4529 size_t used = get_eden_used(); |
4530 size_t capacity = get_eden_capacity(); | |
4531 // Don't start sampling unless we will get sufficiently | |
4532 // many samples. | |
4533 if (used < (capacity/(CMSScheduleRemarkSamplingRatio * 100) | |
4534 * CMSScheduleRemarkEdenPenetration)) { | |
4535 _start_sampling = true; | |
4536 } else { | |
4537 _start_sampling = false; | |
4538 } | |
4539 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
|
4540 CMSPhaseAccounting pa(this, "preclean", _gc_tracer_cm->gc_id(), !PrintGCDetails); |
0 | 4541 preclean_work(CMSPrecleanRefLists1, CMSPrecleanSurvivors1); |
4542 } | |
4543 CMSTokenSync x(true); // is cms thread | |
4544 if (CMSPrecleaningEnabled) { | |
4545 sample_eden(); | |
4546 _collectorState = AbortablePreclean; | |
4547 } else { | |
4548 _collectorState = FinalMarking; | |
4549 } | |
4550 verify_work_stacks_empty(); | |
4551 verify_overflow_empty(); | |
4552 } | |
4553 | |
4554 // Try and schedule the remark such that young gen | |
4555 // occupancy is CMSScheduleRemarkEdenPenetration %. | |
4556 void CMSCollector::abortable_preclean() { | |
4557 check_correct_thread_executing(); | |
4558 assert(CMSPrecleaningEnabled, "Inconsistent control state"); | |
4559 assert(_collectorState == AbortablePreclean, "Inconsistent control state"); | |
4560 | |
4561 // If Eden's current occupancy is below this threshold, | |
4562 // immediately schedule the remark; else preclean | |
4563 // past the next scavenge in an effort to | |
4564 // schedule the pause as described avove. By choosing | |
4565 // CMSScheduleRemarkEdenSizeThreshold >= max eden size | |
4566 // we will never do an actual abortable preclean cycle. | |
4567 if (get_eden_used() > CMSScheduleRemarkEdenSizeThreshold) { | |
4568 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
|
4569 CMSPhaseAccounting pa(this, "abortable-preclean", _gc_tracer_cm->gc_id(), !PrintGCDetails); |
0 | 4570 // We need more smarts in the abortable preclean |
4571 // loop below to deal with cases where allocation | |
4572 // in young gen is very very slow, and our precleaning | |
4573 // is running a losing race against a horde of | |
4574 // mutators intent on flooding us with CMS updates | |
4575 // (dirty cards). | |
4576 // One, admittedly dumb, strategy is to give up | |
4577 // after a certain number of abortable precleaning loops | |
4578 // or after a certain maximum time. We want to make | |
4579 // this smarter in the next iteration. | |
4580 // XXX FIX ME!!! YSR | |
4581 size_t loops = 0, workdone = 0, cumworkdone = 0, waited = 0; | |
4582 while (!(should_abort_preclean() || | |
4583 ConcurrentMarkSweepThread::should_terminate())) { | |
4584 workdone = preclean_work(CMSPrecleanRefLists2, CMSPrecleanSurvivors2); | |
4585 cumworkdone += workdone; | |
4586 loops++; | |
4587 // Voluntarily terminate abortable preclean phase if we have | |
4588 // been at it for too long. | |
4589 if ((CMSMaxAbortablePrecleanLoops != 0) && | |
4590 loops >= CMSMaxAbortablePrecleanLoops) { | |
4591 if (PrintGCDetails) { | |
4592 gclog_or_tty->print(" CMS: abort preclean due to loops "); | |
4593 } | |
4594 break; | |
4595 } | |
4596 if (pa.wallclock_millis() > CMSMaxAbortablePrecleanTime) { | |
4597 if (PrintGCDetails) { | |
4598 gclog_or_tty->print(" CMS: abort preclean due to time "); | |
4599 } | |
4600 break; | |
4601 } | |
4602 // If we are doing little work each iteration, we should | |
4603 // take a short break. | |
4604 if (workdone < CMSAbortablePrecleanMinWorkPerIteration) { | |
4605 // Sleep for some time, waiting for work to accumulate | |
4606 stopTimer(); | |
4607 cmsThread()->wait_on_cms_lock(CMSAbortablePrecleanWaitMillis); | |
4608 startTimer(); | |
4609 waited++; | |
4610 } | |
4611 } | |
4612 if (PrintCMSStatistics > 0) { | |
4613 gclog_or_tty->print(" [%d iterations, %d waits, %d cards)] ", | |
4614 loops, waited, cumworkdone); | |
4615 } | |
4616 } | |
4617 CMSTokenSync x(true); // is cms thread | |
4618 if (_collectorState != Idling) { | |
4619 assert(_collectorState == AbortablePreclean, | |
4620 "Spontaneous state transition?"); | |
4621 _collectorState = FinalMarking; | |
4622 } // Else, a foreground collection completed this CMS cycle. | |
4623 return; | |
4624 } | |
4625 | |
4626 // Respond to an Eden sampling opportunity | |
4627 void CMSCollector::sample_eden() { | |
4628 // Make sure a young gc cannot sneak in between our | |
4629 // reading and recording of a sample. | |
4630 assert(Thread::current()->is_ConcurrentGC_thread(), | |
4631 "Only the cms thread may collect Eden samples"); | |
4632 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
4633 "Should collect samples while holding CMS token"); | |
4634 if (!_start_sampling) { | |
4635 return; | |
4636 } | |
11973
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
4637 // 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
|
4638 // 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
|
4639 if (_eden_chunk_array != NULL && !CMSEdenChunksRecordAlways) { |
0 | 4640 if (_eden_chunk_index < _eden_chunk_capacity) { |
4641 _eden_chunk_array[_eden_chunk_index] = *_top_addr; // take sample | |
4642 assert(_eden_chunk_array[_eden_chunk_index] <= *_end_addr, | |
4643 "Unexpected state of Eden"); | |
4644 // We'd like to check that what we just sampled is an oop-start address; | |
4645 // however, we cannot do that here since the object may not yet have been | |
4646 // initialized. So we'll instead do the check when we _use_ this sample | |
4647 // later. | |
4648 if (_eden_chunk_index == 0 || | |
4649 (pointer_delta(_eden_chunk_array[_eden_chunk_index], | |
4650 _eden_chunk_array[_eden_chunk_index-1]) | |
4651 >= CMSSamplingGrain)) { | |
4652 _eden_chunk_index++; // commit sample | |
4653 } | |
4654 } | |
4655 } | |
4656 if ((_collectorState == AbortablePreclean) && !_abort_preclean) { | |
4657 size_t used = get_eden_used(); | |
4658 size_t capacity = get_eden_capacity(); | |
4659 assert(used <= capacity, "Unexpected state of Eden"); | |
4660 if (used > (capacity/100 * CMSScheduleRemarkEdenPenetration)) { | |
4661 _abort_preclean = true; | |
4662 } | |
4663 } | |
4664 } | |
4665 | |
4666 | |
4667 size_t CMSCollector::preclean_work(bool clean_refs, bool clean_survivor) { | |
4668 assert(_collectorState == Precleaning || | |
4669 _collectorState == AbortablePreclean, "incorrect state"); | |
4670 ResourceMark rm; | |
4671 HandleMark hm; | |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
4672 |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
4673 // Precleaning is currently not MT but the reference processor |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
4674 // may be set for MT. Disable it temporarily here. |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
4675 ReferenceProcessor* rp = ref_processor(); |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
4676 ReferenceProcessorMTDiscoveryMutator rp_mut_discovery(rp, false); |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
4677 |
0 | 4678 // Do one pass of scrubbing the discovered reference lists |
4679 // to remove any reference objects with strongly-reachable | |
4680 // referents. | |
4681 if (clean_refs) { | |
4682 CMSPrecleanRefsYieldClosure yield_cl(this); | |
4683 assert(rp->span().equals(_span), "Spans should be equal"); | |
4684 CMSKeepAliveClosure keep_alive(this, _span, &_markBitMap, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4685 &_markStack, true /* preclean */); |
0 | 4686 CMSDrainMarkingStackClosure complete_trace(this, |
452
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
4687 _span, &_markBitMap, &_markStack, |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
4688 &keep_alive, true /* preclean */); |
0 | 4689 |
4690 // We don't want this step to interfere with a young | |
4691 // collection because we don't want to take CPU | |
4692 // or memory bandwidth away from the young GC threads | |
4693 // (which may be as many as there are CPUs). | |
4694 // Note that we don't need to protect ourselves from | |
4695 // interference with mutators because they can't | |
4696 // manipulate the discovered reference lists nor affect | |
4697 // the computed reachability of the referents, the | |
4698 // only properties manipulated by the precleaning | |
4699 // of these reference lists. | |
4700 stopTimer(); | |
4701 CMSTokenSyncWithLocks x(true /* is cms thread */, | |
4702 bitMapLock()); | |
4703 startTimer(); | |
4704 sample_eden(); | |
935 | 4705 |
0 | 4706 // The following will yield to allow foreground |
4707 // collection to proceed promptly. XXX YSR: | |
4708 // The code in this method may need further | |
4709 // tweaking for better performance and some restructuring | |
4710 // for cleaner interfaces. | |
10405 | 4711 GCTimer *gc_timer = NULL; // Currently not tracing concurrent phases |
0 | 4712 rp->preclean_discovered_references( |
10405 | 4713 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
|
4714 gc_timer, _gc_tracer_cm->gc_id()); |
0 | 4715 } |
4716 | |
4717 if (clean_survivor) { // preclean the active survivor space(s) | |
4718 assert(_young_gen->kind() == Generation::DefNew || | |
4719 _young_gen->kind() == Generation::ParNew || | |
4720 _young_gen->kind() == Generation::ASParNew, | |
4721 "incorrect type for cast"); | |
4722 DefNewGeneration* dng = (DefNewGeneration*)_young_gen; | |
4723 PushAndMarkClosure pam_cl(this, _span, ref_processor(), | |
4724 &_markBitMap, &_modUnionTable, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4725 &_markStack, true /* precleaning phase */); |
0 | 4726 stopTimer(); |
4727 CMSTokenSyncWithLocks ts(true /* is cms thread */, | |
4728 bitMapLock()); | |
4729 startTimer(); | |
4730 unsigned int before_count = | |
4731 GenCollectedHeap::heap()->total_collections(); | |
4732 SurvivorSpacePrecleanClosure | |
4733 sss_cl(this, _span, &_markBitMap, &_markStack, | |
4734 &pam_cl, before_count, CMSYield); | |
4735 dng->from()->object_iterate_careful(&sss_cl); | |
4736 dng->to()->object_iterate_careful(&sss_cl); | |
4737 } | |
4738 MarkRefsIntoAndScanClosure | |
4739 mrias_cl(_span, ref_processor(), &_markBitMap, &_modUnionTable, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4740 &_markStack, this, CMSYield, |
0 | 4741 true /* precleaning phase */); |
4742 // CAUTION: The following closure has persistent state that may need to | |
4743 // be reset upon a decrease in the sequence of addresses it | |
4744 // processes. | |
4745 ScanMarkedObjectsAgainCarefullyClosure | |
4746 smoac_cl(this, _span, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4747 &_markBitMap, &_markStack, &mrias_cl, CMSYield); |
0 | 4748 |
4749 // Preclean dirty cards in ModUnionTable and CardTable using | |
4750 // appropriate convergence criterion; | |
4751 // repeat CMSPrecleanIter times unless we find that | |
4752 // we are losing. | |
4753 assert(CMSPrecleanIter < 10, "CMSPrecleanIter is too large"); | |
4754 assert(CMSPrecleanNumerator < CMSPrecleanDenominator, | |
4755 "Bad convergence multiplier"); | |
4756 assert(CMSPrecleanThreshold >= 100, | |
4757 "Unreasonably low CMSPrecleanThreshold"); | |
4758 | |
4759 size_t numIter, cumNumCards, lastNumCards, curNumCards; | |
4760 for (numIter = 0, cumNumCards = lastNumCards = curNumCards = 0; | |
4761 numIter < CMSPrecleanIter; | |
4762 numIter++, lastNumCards = curNumCards, cumNumCards += curNumCards) { | |
4763 curNumCards = preclean_mod_union_table(_cmsGen, &smoac_cl); | |
4764 if (Verbose && PrintGCDetails) { | |
4765 gclog_or_tty->print(" (modUnionTable: %d cards)", curNumCards); | |
4766 } | |
4767 // Either there are very few dirty cards, so re-mark | |
4768 // pause will be small anyway, or our pre-cleaning isn't | |
4769 // that much faster than the rate at which cards are being | |
4770 // dirtied, so we might as well stop and re-mark since | |
4771 // precleaning won't improve our re-mark time by much. | |
4772 if (curNumCards <= CMSPrecleanThreshold || | |
4773 (numIter > 0 && | |
4774 (curNumCards * CMSPrecleanDenominator > | |
4775 lastNumCards * CMSPrecleanNumerator))) { | |
4776 numIter++; | |
4777 cumNumCards += curNumCards; | |
4778 break; | |
4779 } | |
4780 } | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4781 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4782 preclean_klasses(&mrias_cl, _cmsGen->freelistLock()); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4783 |
0 | 4784 curNumCards = preclean_card_table(_cmsGen, &smoac_cl); |
4785 cumNumCards += curNumCards; | |
4786 if (PrintGCDetails && PrintCMSStatistics != 0) { | |
4787 gclog_or_tty->print_cr(" (cardTable: %d cards, re-scanned %d cards, %d iterations)", | |
4788 curNumCards, cumNumCards, numIter); | |
4789 } | |
4790 return cumNumCards; // as a measure of useful work done | |
4791 } | |
4792 | |
4793 // PRECLEANING NOTES: | |
4794 // Precleaning involves: | |
4795 // . reading the bits of the modUnionTable and clearing the set bits. | |
4796 // . For the cards corresponding to the set bits, we scan the | |
4797 // objects on those cards. This means we need the free_list_lock | |
4798 // so that we can safely iterate over the CMS space when scanning | |
4799 // for oops. | |
4800 // . When we scan the objects, we'll be both reading and setting | |
4801 // marks in the marking bit map, so we'll need the marking bit map. | |
4802 // . For protecting _collector_state transitions, we take the CGC_lock. | |
4803 // Note that any races in the reading of of card table entries by the | |
4804 // CMS thread on the one hand and the clearing of those entries by the | |
4805 // VM thread or the setting of those entries by the mutator threads on the | |
4806 // other are quite benign. However, for efficiency it makes sense to keep | |
4807 // the VM thread from racing with the CMS thread while the latter is | |
4808 // dirty card info to the modUnionTable. We therefore also use the | |
4809 // CGC_lock to protect the reading of the card table and the mod union | |
4810 // table by the CM thread. | |
4811 // . We run concurrently with mutator updates, so scanning | |
4812 // needs to be done carefully -- we should not try to scan | |
4813 // potentially uninitialized objects. | |
4814 // | |
4815 // Locking strategy: While holding the CGC_lock, we scan over and | |
4816 // reset a maximal dirty range of the mod union / card tables, then lock | |
4817 // the free_list_lock and bitmap lock to do a full marking, then | |
4818 // release these locks; and repeat the cycle. This allows for a | |
4819 // certain amount of fairness in the sharing of these locks between | |
4820 // the CMS collector on the one hand, and the VM thread and the | |
4821 // mutators on the other. | |
4822 | |
4823 // NOTE: preclean_mod_union_table() and preclean_card_table() | |
4824 // further below are largely identical; if you need to modify | |
4825 // one of these methods, please check the other method too. | |
4826 | |
4827 size_t CMSCollector::preclean_mod_union_table( | |
4828 ConcurrentMarkSweepGeneration* gen, | |
4829 ScanMarkedObjectsAgainCarefullyClosure* cl) { | |
4830 verify_work_stacks_empty(); | |
4831 verify_overflow_empty(); | |
4832 | |
4833 // strategy: starting with the first card, accumulate contiguous | |
4834 // ranges of dirty cards; clear these cards, then scan the region | |
4835 // covered by these cards. | |
4836 | |
4837 // Since all of the MUT is committed ahead, we can just use | |
4838 // that, in case the generations expand while we are precleaning. | |
4839 // It might also be fine to just use the committed part of the | |
4840 // generation, but we might potentially miss cards when the | |
4841 // generation is rapidly expanding while we are in the midst | |
4842 // of precleaning. | |
4843 HeapWord* startAddr = gen->reserved().start(); | |
4844 HeapWord* endAddr = gen->reserved().end(); | |
4845 | |
4846 cl->setFreelistLock(gen->freelistLock()); // needed for yielding | |
4847 | |
4848 size_t numDirtyCards, cumNumDirtyCards; | |
4849 HeapWord *nextAddr, *lastAddr; | |
4850 for (cumNumDirtyCards = numDirtyCards = 0, | |
4851 nextAddr = lastAddr = startAddr; | |
4852 nextAddr < endAddr; | |
4853 nextAddr = lastAddr, cumNumDirtyCards += numDirtyCards) { | |
4854 | |
4855 ResourceMark rm; | |
4856 HandleMark hm; | |
4857 | |
4858 MemRegion dirtyRegion; | |
4859 { | |
4860 stopTimer(); | |
935 | 4861 // Potential yield point |
0 | 4862 CMSTokenSync ts(true); |
4863 startTimer(); | |
4864 sample_eden(); | |
4865 // Get dirty region starting at nextOffset (inclusive), | |
4866 // simultaneously clearing it. | |
4867 dirtyRegion = | |
4868 _modUnionTable.getAndClearMarkedRegion(nextAddr, endAddr); | |
4869 assert(dirtyRegion.start() >= nextAddr, | |
4870 "returned region inconsistent?"); | |
4871 } | |
4872 // Remember where the next search should begin. | |
4873 // The returned region (if non-empty) is a right open interval, | |
4874 // so lastOffset is obtained from the right end of that | |
4875 // interval. | |
4876 lastAddr = dirtyRegion.end(); | |
4877 // Should do something more transparent and less hacky XXX | |
4878 numDirtyCards = | |
4879 _modUnionTable.heapWordDiffToOffsetDiff(dirtyRegion.word_size()); | |
4880 | |
4881 // We'll scan the cards in the dirty region (with periodic | |
4882 // yields for foreground GC as needed). | |
4883 if (!dirtyRegion.is_empty()) { | |
4884 assert(numDirtyCards > 0, "consistency check"); | |
4885 HeapWord* stop_point = NULL; | |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
4886 stopTimer(); |
935 | 4887 // Potential yield point |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
4888 CMSTokenSyncWithLocks ts(true, gen->freelistLock(), |
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
4889 bitMapLock()); |
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
4890 startTimer(); |
0 | 4891 { |
4892 verify_work_stacks_empty(); | |
4893 verify_overflow_empty(); | |
4894 sample_eden(); | |
4895 stop_point = | |
4896 gen->cmsSpace()->object_iterate_careful_m(dirtyRegion, cl); | |
4897 } | |
4898 if (stop_point != NULL) { | |
4899 // The careful iteration stopped early either because it found an | |
4900 // uninitialized object, or because we were in the midst of an | |
4901 // "abortable preclean", which should now be aborted. Redirty | |
4902 // the bits corresponding to the partially-scanned or unscanned | |
4903 // cards. We'll either restart at the next block boundary or | |
4904 // abort the preclean. | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4905 assert((_collectorState == AbortablePreclean && should_abort_preclean()), |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4906 "Should only be AbortablePreclean."); |
0 | 4907 _modUnionTable.mark_range(MemRegion(stop_point, dirtyRegion.end())); |
4908 if (should_abort_preclean()) { | |
4909 break; // out of preclean loop | |
4910 } else { | |
4911 // Compute the next address at which preclean should pick up; | |
4912 // might need bitMapLock in order to read P-bits. | |
4913 lastAddr = next_card_start_after_block(stop_point); | |
4914 } | |
4915 } | |
4916 } else { | |
4917 assert(lastAddr == endAddr, "consistency check"); | |
4918 assert(numDirtyCards == 0, "consistency check"); | |
4919 break; | |
4920 } | |
4921 } | |
4922 verify_work_stacks_empty(); | |
4923 verify_overflow_empty(); | |
4924 return cumNumDirtyCards; | |
4925 } | |
4926 | |
4927 // NOTE: preclean_mod_union_table() above and preclean_card_table() | |
4928 // below are largely identical; if you need to modify | |
4929 // one of these methods, please check the other method too. | |
4930 | |
4931 size_t CMSCollector::preclean_card_table(ConcurrentMarkSweepGeneration* gen, | |
4932 ScanMarkedObjectsAgainCarefullyClosure* cl) { | |
4933 // strategy: it's similar to precleamModUnionTable above, in that | |
4934 // we accumulate contiguous ranges of dirty cards, mark these cards | |
4935 // precleaned, then scan the region covered by these cards. | |
4936 HeapWord* endAddr = (HeapWord*)(gen->_virtual_space.high()); | |
4937 HeapWord* startAddr = (HeapWord*)(gen->_virtual_space.low()); | |
4938 | |
4939 cl->setFreelistLock(gen->freelistLock()); // needed for yielding | |
4940 | |
4941 size_t numDirtyCards, cumNumDirtyCards; | |
4942 HeapWord *lastAddr, *nextAddr; | |
4943 | |
4944 for (cumNumDirtyCards = numDirtyCards = 0, | |
4945 nextAddr = lastAddr = startAddr; | |
4946 nextAddr < endAddr; | |
4947 nextAddr = lastAddr, cumNumDirtyCards += numDirtyCards) { | |
4948 | |
4949 ResourceMark rm; | |
4950 HandleMark hm; | |
4951 | |
4952 MemRegion dirtyRegion; | |
4953 { | |
4954 // See comments in "Precleaning notes" above on why we | |
4955 // do this locking. XXX Could the locking overheads be | |
4956 // too high when dirty cards are sparse? [I don't think so.] | |
4957 stopTimer(); | |
4958 CMSTokenSync x(true); // is cms thread | |
4959 startTimer(); | |
4960 sample_eden(); | |
4961 // Get and clear dirty region from card table | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
4962 dirtyRegion = _ct->ct_bs()->dirty_card_range_after_reset( |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
4963 MemRegion(nextAddr, endAddr), |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
4964 true, |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
4965 CardTableModRefBS::precleaned_card_val()); |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
4966 |
0 | 4967 assert(dirtyRegion.start() >= nextAddr, |
4968 "returned region inconsistent?"); | |
4969 } | |
4970 lastAddr = dirtyRegion.end(); | |
4971 numDirtyCards = | |
4972 dirtyRegion.word_size()/CardTableModRefBS::card_size_in_words; | |
4973 | |
4974 if (!dirtyRegion.is_empty()) { | |
4975 stopTimer(); | |
4976 CMSTokenSyncWithLocks ts(true, gen->freelistLock(), bitMapLock()); | |
4977 startTimer(); | |
4978 sample_eden(); | |
4979 verify_work_stacks_empty(); | |
4980 verify_overflow_empty(); | |
4981 HeapWord* stop_point = | |
4982 gen->cmsSpace()->object_iterate_careful_m(dirtyRegion, cl); | |
4983 if (stop_point != NULL) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4984 assert((_collectorState == AbortablePreclean && should_abort_preclean()), |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4985 "Should only be AbortablePreclean."); |
0 | 4986 _ct->ct_bs()->invalidate(MemRegion(stop_point, dirtyRegion.end())); |
4987 if (should_abort_preclean()) { | |
4988 break; // out of preclean loop | |
4989 } else { | |
4990 // Compute the next address at which preclean should pick up. | |
4991 lastAddr = next_card_start_after_block(stop_point); | |
4992 } | |
4993 } | |
4994 } else { | |
4995 break; | |
4996 } | |
4997 } | |
4998 verify_work_stacks_empty(); | |
4999 verify_overflow_empty(); | |
5000 return cumNumDirtyCards; | |
5001 } | |
5002 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5003 class PrecleanKlassClosure : public KlassClosure { |
20268
4c1b88a53c74
8046670: Make CMS metadata aware closures applicable for other collectors
stefank
parents:
20264
diff
changeset
|
5004 KlassToOopClosure _cm_klass_closure; |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5005 public: |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5006 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
|
5007 void do_klass(Klass* k) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5008 if (k->has_accumulated_modified_oops()) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5009 k->clear_accumulated_modified_oops(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5010 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5011 _cm_klass_closure.do_klass(k); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5012 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5013 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5014 }; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5015 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5016 // 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
|
5017 void CMSCollector::preclean_klasses(MarkRefsIntoAndScanClosure* cl, Mutex* freelistLock) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5018 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5019 cl->set_freelistLock(freelistLock); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5020 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5021 CMSTokenSyncWithLocks ts(true, freelistLock, bitMapLock()); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5022 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5023 // 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
|
5024 // 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
|
5025 PrecleanKlassClosure preclean_klass_closure(cl); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5026 ClassLoaderDataGraph::classes_do(&preclean_klass_closure); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5027 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5028 verify_work_stacks_empty(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5029 verify_overflow_empty(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5030 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5031 |
0 | 5032 void CMSCollector::checkpointRootsFinal(bool asynch, |
5033 bool clear_all_soft_refs, bool init_mark_was_synchronous) { | |
5034 assert(_collectorState == FinalMarking, "incorrect state transition?"); | |
5035 check_correct_thread_executing(); | |
5036 // world is stopped at this checkpoint | |
5037 assert(SafepointSynchronize::is_at_safepoint(), | |
5038 "world should be stopped"); | |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
3293
diff
changeset
|
5039 TraceCMSMemoryManagerStats tms(_collectorState,GenCollectedHeap::heap()->gc_cause()); |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
3293
diff
changeset
|
5040 |
0 | 5041 verify_work_stacks_empty(); |
5042 verify_overflow_empty(); | |
5043 | |
5044 SpecializationStats::clear(); | |
5045 if (PrintGCDetails) { | |
5046 gclog_or_tty->print("[YG occupancy: "SIZE_FORMAT" K ("SIZE_FORMAT" K)]", | |
5047 _young_gen->used() / K, | |
5048 _young_gen->capacity() / K); | |
5049 } | |
5050 if (asynch) { | |
5051 if (CMSScavengeBeforeRemark) { | |
5052 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
5053 // Temporarily set flag to false, GCH->do_collection will | |
5054 // expect it to be false and set to true | |
5055 FlagSetting fl(gch->_is_gc_active, false); | |
10405 | 5056 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
|
5057 PrintGCDetails && Verbose, true, _gc_timer_cm, _gc_tracer_cm->gc_id());) |
0 | 5058 int level = _cmsGen->level() - 1; |
5059 if (level >= 0) { | |
5060 gch->do_collection(true, // full (i.e. force, see below) | |
5061 false, // !clear_all_soft_refs | |
5062 0, // size | |
5063 false, // is_tlab | |
5064 level // max_level | |
5065 ); | |
5066 } | |
5067 } | |
5068 FreelistLocker x(this); | |
5069 MutexLockerEx y(bitMapLock(), | |
5070 Mutex::_no_safepoint_check_flag); | |
5071 assert(!init_mark_was_synchronous, "but that's impossible!"); | |
5072 checkpointRootsFinalWork(asynch, clear_all_soft_refs, false); | |
5073 } else { | |
5074 // already have all the locks | |
5075 checkpointRootsFinalWork(asynch, clear_all_soft_refs, | |
5076 init_mark_was_synchronous); | |
5077 } | |
5078 verify_work_stacks_empty(); | |
5079 verify_overflow_empty(); | |
5080 SpecializationStats::print(); | |
5081 } | |
5082 | |
5083 void CMSCollector::checkpointRootsFinalWork(bool asynch, | |
5084 bool clear_all_soft_refs, bool init_mark_was_synchronous) { | |
5085 | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
5086 NOT_PRODUCT(GCTraceTime tr("checkpointRootsFinalWork", PrintGCDetails, false, _gc_timer_cm, _gc_tracer_cm->gc_id());) |
0 | 5087 |
5088 assert(haveFreelistLocks(), "must have free list locks"); | |
5089 assert_lock_strong(bitMapLock()); | |
5090 | |
5091 if (UseAdaptiveSizePolicy) { | |
5092 size_policy()->checkpoint_roots_final_begin(); | |
5093 } | |
5094 | |
5095 ResourceMark rm; | |
5096 HandleMark hm; | |
5097 | |
5098 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
5099 | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
5100 if (should_unload_classes()) { |
0 | 5101 CodeCache::gc_prologue(); |
5102 } | |
5103 assert(haveFreelistLocks(), "must have free list locks"); | |
5104 assert_lock_strong(bitMapLock()); | |
5105 | |
5106 if (!init_mark_was_synchronous) { | |
5107 // We might assume that we need not fill TLAB's when | |
5108 // CMSScavengeBeforeRemark is set, because we may have just done | |
5109 // a scavenge which would have filled all TLAB's -- and besides | |
5110 // Eden would be empty. This however may not always be the case -- | |
5111 // for instance although we asked for a scavenge, it may not have | |
5112 // happened because of a JNI critical section. We probably need | |
5113 // a policy for deciding whether we can in that case wait until | |
5114 // the critical section releases and then do the remark following | |
5115 // the scavenge, and skip it here. In the absence of that policy, | |
5116 // or of an indication of whether the scavenge did indeed occur, | |
5117 // we cannot rely on TLAB's having been filled and must do | |
5118 // so here just in case a scavenge did not happen. | |
5119 gch->ensure_parsability(false); // fill TLAB's, but no need to retire them | |
5120 // Update the saved marks which may affect the root scans. | |
5121 gch->save_marks(); | |
5122 | |
11973
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5123 if (CMSPrintEdenSurvivorChunks) { |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5124 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
|
5125 } |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5126 |
0 | 5127 { |
22294
d86b226e331a
Enable derived oop processing by the GC with JVMCI
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
20804
diff
changeset
|
5128 #if defined(COMPILER2) || defined(JVMCI) |
d86b226e331a
Enable derived oop processing by the GC with JVMCI
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
20804
diff
changeset
|
5129 DerivedPointerTableDeactivate dpt_deact; |
d86b226e331a
Enable derived oop processing by the GC with JVMCI
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
20804
diff
changeset
|
5130 #endif |
0 | 5131 |
5132 // Note on the role of the mod union table: | |
5133 // Since the marker in "markFromRoots" marks concurrently with | |
5134 // mutators, it is possible for some reachable objects not to have been | |
5135 // scanned. For instance, an only reference to an object A was | |
5136 // placed in object B after the marker scanned B. Unless B is rescanned, | |
5137 // A would be collected. Such updates to references in marked objects | |
5138 // are detected via the mod union table which is the set of all cards | |
5139 // dirtied since the first checkpoint in this GC cycle and prior to | |
5140 // the most recent young generation GC, minus those cleaned up by the | |
5141 // concurrent precleaning. | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5142 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
|
5143 GCTraceTime t("Rescan (parallel) ", PrintGCDetails, false, _gc_timer_cm, _gc_tracer_cm->gc_id()); |
0 | 5144 do_remark_parallel(); |
5145 } else { | |
10405 | 5146 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
|
5147 _gc_timer_cm, _gc_tracer_cm->gc_id()); |
0 | 5148 do_remark_non_parallel(); |
5149 } | |
5150 } | |
5151 } else { | |
5152 assert(!asynch, "Can't have init_mark_was_synchronous in asynch mode"); | |
5153 // The initial mark was stop-world, so there's no rescanning to | |
5154 // do; go straight on to the next step below. | |
5155 } | |
5156 verify_work_stacks_empty(); | |
5157 verify_overflow_empty(); | |
5158 | |
5159 { | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
5160 NOT_PRODUCT(GCTraceTime ts("refProcessingWork", PrintGCDetails, false, _gc_timer_cm, _gc_tracer_cm->gc_id());) |
0 | 5161 refProcessingWork(asynch, clear_all_soft_refs); |
5162 } | |
5163 verify_work_stacks_empty(); | |
5164 verify_overflow_empty(); | |
5165 | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
5166 if (should_unload_classes()) { |
0 | 5167 CodeCache::gc_epilogue(); |
5168 } | |
2147
9afee0b9fc1d
7012505: BreakpointWithFullGC.sh fails with Internal Error (src/share/vm/oops/methodOop.cpp:220)
kamg
parents:
2137
diff
changeset
|
5169 JvmtiExport::gc_epilogue(); |
0 | 5170 |
5171 // If we encountered any (marking stack / work queue) overflow | |
5172 // events during the current CMS cycle, take appropriate | |
5173 // remedial measures, where possible, so as to try and avoid | |
5174 // recurrence of that condition. | |
5175 assert(_markStack.isEmpty(), "No grey objects"); | |
5176 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
|
5177 _ser_kac_ovflw + _ser_kac_preclean_ovflw; |
0 | 5178 if (ser_ovflw > 0) { |
5179 if (PrintCMSStatistics != 0) { | |
5180 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
|
5181 "(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
|
5182 ", kac_preclean="SIZE_FORMAT")", |
0 | 5183 _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
|
5184 _ser_kac_ovflw, _ser_kac_preclean_ovflw); |
0 | 5185 } |
5186 _markStack.expand(); | |
5187 _ser_pmc_remark_ovflw = 0; | |
5188 _ser_pmc_preclean_ovflw = 0; | |
452
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
5189 _ser_kac_preclean_ovflw = 0; |
0 | 5190 _ser_kac_ovflw = 0; |
5191 } | |
5192 if (_par_pmc_remark_ovflw > 0 || _par_kac_ovflw > 0) { | |
5193 if (PrintCMSStatistics != 0) { | |
5194 gclog_or_tty->print_cr("Work queue overflow (benign) " | |
5195 "(pmc_rm="SIZE_FORMAT", kac="SIZE_FORMAT")", | |
5196 _par_pmc_remark_ovflw, _par_kac_ovflw); | |
5197 } | |
5198 _par_pmc_remark_ovflw = 0; | |
5199 _par_kac_ovflw = 0; | |
5200 } | |
5201 if (PrintCMSStatistics != 0) { | |
5202 if (_markStack._hit_limit > 0) { | |
5203 gclog_or_tty->print_cr(" (benign) Hit max stack size limit ("SIZE_FORMAT")", | |
5204 _markStack._hit_limit); | |
5205 } | |
5206 if (_markStack._failed_double > 0) { | |
5207 gclog_or_tty->print_cr(" (benign) Failed stack doubling ("SIZE_FORMAT")," | |
5208 " current capacity "SIZE_FORMAT, | |
5209 _markStack._failed_double, | |
5210 _markStack.capacity()); | |
5211 } | |
5212 } | |
5213 _markStack._hit_limit = 0; | |
5214 _markStack._failed_double = 0; | |
5215 | |
5216 if ((VerifyAfterGC || VerifyDuringGC) && | |
5217 GenCollectedHeap::heap()->total_collections() >= VerifyGCStartAt) { | |
5218 verify_after_remark(); | |
5219 } | |
5220 | |
10405 | 5221 _gc_tracer_cm->report_object_count_after_gc(&_is_alive_closure); |
5222 | |
0 | 5223 // Change under the freelistLocks. |
5224 _collectorState = Sweeping; | |
5225 // Call isAllClear() under bitMapLock | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5226 assert(_modUnionTable.isAllClear(), |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5227 "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
|
5228 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
|
5229 "Should be clear by end of the final marking"); |
0 | 5230 if (UseAdaptiveSizePolicy) { |
5231 size_policy()->checkpoint_roots_final_end(gch->gc_cause()); | |
5232 } | |
5233 } | |
5234 | |
11975 | 5235 void CMSParInitialMarkTask::work(uint worker_id) { |
5236 elapsedTimer _timer; | |
5237 ResourceMark rm; | |
5238 HandleMark hm; | |
5239 | |
5240 // ---------- scan from roots -------------- | |
5241 _timer.start(); | |
5242 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
5243 Par_MarkRefsIntoClosure par_mri_cl(_collector->_span, &(_collector->_markBitMap)); | |
5244 | |
5245 // ---------- young gen roots -------------- | |
5246 { | |
5247 work_on_young_gen_roots(worker_id, &par_mri_cl); | |
5248 _timer.stop(); | |
5249 if (PrintCMSStatistics != 0) { | |
5250 gclog_or_tty->print_cr( | |
5251 "Finished young gen initial mark scan work in %dth thread: %3.3f sec", | |
5252 worker_id, _timer.seconds()); | |
5253 } | |
5254 } | |
5255 | |
5256 // ---------- remaining roots -------------- | |
5257 _timer.reset(); | |
5258 _timer.start(); | |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5259 |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5260 CLDToOopClosure cld_closure(&par_mri_cl, true); |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5261 |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5262 gch->gen_process_roots(_collector->_cmsGen->level(), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5263 false, // yg was scanned above |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5264 false, // this is parallel code |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5265 SharedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5266 _collector->should_unload_classes(), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5267 &par_mri_cl, |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5268 NULL, |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5269 &cld_closure); |
11975 | 5270 assert(_collector->should_unload_classes() |
20254
9fec19bb0659
8032379: Remove the is_scavenging flag to process_strong_roots
mgerdin
parents:
20197
diff
changeset
|
5271 || (_collector->CMSCollector::roots_scanning_options() & SharedHeap::SO_AllCodeCache), |
11975 | 5272 "if we didn't scan the code cache, we have to be ready to drop nmethods with expired weak oops"); |
5273 _timer.stop(); | |
5274 if (PrintCMSStatistics != 0) { | |
5275 gclog_or_tty->print_cr( | |
5276 "Finished remaining root initial mark scan work in %dth thread: %3.3f sec", | |
5277 worker_id, _timer.seconds()); | |
5278 } | |
5279 } | |
5280 | |
0 | 5281 // Parallel remark task |
11975 | 5282 class CMSParRemarkTask: public CMSParMarkTask { |
0 | 5283 CompactibleFreeListSpace* _cms_space; |
5284 | |
5285 // The per-thread work queues, available here for stealing. | |
5286 OopTaskQueueSet* _task_queues; | |
5287 ParallelTaskTerminator _term; | |
5288 | |
5289 public: | |
4095
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5290 // 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
|
5291 // workers to be taken from the active workers in the work gang. |
0 | 5292 CMSParRemarkTask(CMSCollector* collector, |
5293 CompactibleFreeListSpace* cms_space, | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5294 int n_workers, FlexibleWorkGang* workers, |
0 | 5295 OopTaskQueueSet* task_queues): |
11975 | 5296 CMSParMarkTask("Rescan roots and grey objects in parallel", |
5297 collector, n_workers), | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5298 _cms_space(cms_space), |
0 | 5299 _task_queues(task_queues), |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5300 _term(n_workers, task_queues) { } |
0 | 5301 |
5302 OopTaskQueueSet* task_queues() { return _task_queues; } | |
5303 | |
5304 OopTaskQueue* work_queue(int i) { return task_queues()->queue(i); } | |
5305 | |
5306 ParallelTaskTerminator* terminator() { return &_term; } | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5307 int n_workers() { return _n_workers; } |
0 | 5308 |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5309 void work(uint worker_id); |
0 | 5310 |
5311 private: | |
5312 // ... of dirty cards in old space | |
5313 void do_dirty_card_rescan_tasks(CompactibleFreeListSpace* sp, int i, | |
5314 Par_MarkRefsIntoAndScanClosure* cl); | |
5315 | |
5316 // ... work stealing for the above | |
5317 void do_work_steal(int i, Par_MarkRefsIntoAndScanClosure* cl, int* seed); | |
5318 }; | |
5319 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5320 class RemarkKlassClosure : public KlassClosure { |
20268
4c1b88a53c74
8046670: Make CMS metadata aware closures applicable for other collectors
stefank
parents:
20264
diff
changeset
|
5321 KlassToOopClosure _cm_klass_closure; |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5322 public: |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5323 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
|
5324 void do_klass(Klass* k) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5325 // 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
|
5326 if (k->has_accumulated_modified_oops()) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5327 k->clear_accumulated_modified_oops(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5328 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5329 // 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
|
5330 // 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
|
5331 } else if (k->has_modified_oops()) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5332 // 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
|
5333 } else { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5334 // No modified oops in the Klass. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5335 return; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5336 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5337 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5338 // 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
|
5339 _cm_klass_closure.do_klass(k); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5340 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5341 }; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5342 |
11975 | 5343 void CMSParMarkTask::work_on_young_gen_roots(uint worker_id, OopsInGenClosure* cl) { |
5344 DefNewGeneration* dng = _collector->_young_gen->as_DefNewGeneration(); | |
5345 EdenSpace* eden_space = dng->eden(); | |
5346 ContiguousSpace* from_space = dng->from(); | |
5347 ContiguousSpace* to_space = dng->to(); | |
5348 | |
5349 HeapWord** eca = _collector->_eden_chunk_array; | |
5350 size_t ect = _collector->_eden_chunk_index; | |
5351 HeapWord** sca = _collector->_survivor_chunk_array; | |
5352 size_t sct = _collector->_survivor_chunk_index; | |
5353 | |
5354 assert(ect <= _collector->_eden_chunk_capacity, "out of bounds"); | |
5355 assert(sct <= _collector->_survivor_chunk_capacity, "out of bounds"); | |
5356 | |
5357 do_young_space_rescan(worker_id, cl, to_space, NULL, 0); | |
5358 do_young_space_rescan(worker_id, cl, from_space, sca, sct); | |
5359 do_young_space_rescan(worker_id, cl, eden_space, eca, ect); | |
5360 } | |
5361 | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5362 // work_queue(i) is passed to the closure |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5363 // Par_MarkRefsIntoAndScanClosure. The "i" parameter |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5364 // 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
|
5365 // do_work_steal() to select the i-th task_queue. |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5366 |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5367 void CMSParRemarkTask::work(uint worker_id) { |
0 | 5368 elapsedTimer _timer; |
5369 ResourceMark rm; | |
5370 HandleMark hm; | |
5371 | |
5372 // ---------- rescan from roots -------------- | |
5373 _timer.start(); | |
5374 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
5375 Par_MarkRefsIntoAndScanClosure par_mrias_cl(_collector, | |
5376 _collector->_span, _collector->ref_processor(), | |
5377 &(_collector->_markBitMap), | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5378 work_queue(worker_id)); |
0 | 5379 |
5380 // Rescan young gen roots first since these are likely | |
5381 // coarsely partitioned and may, on that account, constitute | |
5382 // the critical path; thus, it's best to start off that | |
5383 // work first. | |
5384 // ---------- young gen roots -------------- | |
5385 { | |
11975 | 5386 work_on_young_gen_roots(worker_id, &par_mrias_cl); |
0 | 5387 _timer.stop(); |
5388 if (PrintCMSStatistics != 0) { | |
5389 gclog_or_tty->print_cr( | |
5390 "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
|
5391 worker_id, _timer.seconds()); |
0 | 5392 } |
5393 } | |
5394 | |
5395 // ---------- remaining roots -------------- | |
5396 _timer.reset(); | |
5397 _timer.start(); | |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5398 gch->gen_process_roots(_collector->_cmsGen->level(), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5399 false, // yg was scanned above |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5400 false, // this is parallel code |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5401 SharedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5402 _collector->should_unload_classes(), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5403 &par_mrias_cl, |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5404 NULL, |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5405 NULL); // The dirty klasses will be handled below |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5406 |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
5407 assert(_collector->should_unload_classes() |
20254
9fec19bb0659
8032379: Remove the is_scavenging flag to process_strong_roots
mgerdin
parents:
20197
diff
changeset
|
5408 || (_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
|
5409 "if we didn't scan the code cache, we have to be ready to drop nmethods with expired weak oops"); |
0 | 5410 _timer.stop(); |
5411 if (PrintCMSStatistics != 0) { | |
5412 gclog_or_tty->print_cr( | |
5413 "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
|
5414 worker_id, _timer.seconds()); |
0 | 5415 } |
5416 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5417 // ---------- unhandled CLD scanning ---------- |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5418 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
|
5419 _timer.reset(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5420 _timer.start(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5421 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5422 // 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
|
5423 // introduced during concurrent marking. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5424 ResourceMark rm; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5425 GrowableArray<ClassLoaderData*>* array = ClassLoaderDataGraph::new_clds(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5426 for (int i = 0; i < array->length(); i++) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5427 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
|
5428 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5429 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5430 // 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
|
5431 ClassLoaderDataGraph::remember_new_clds(false); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5432 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5433 _timer.stop(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5434 if (PrintCMSStatistics != 0) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5435 gclog_or_tty->print_cr( |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5436 "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
|
5437 worker_id, _timer.seconds()); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5438 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5439 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5440 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5441 // ---------- dirty klass scanning ---------- |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5442 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
|
5443 _timer.reset(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5444 _timer.start(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5445 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5446 // 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
|
5447 RemarkKlassClosure remark_klass_closure(&par_mrias_cl); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5448 ClassLoaderDataGraph::classes_do(&remark_klass_closure); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5449 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5450 _timer.stop(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5451 if (PrintCMSStatistics != 0) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5452 gclog_or_tty->print_cr( |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5453 "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
|
5454 worker_id, _timer.seconds()); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5455 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5456 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5457 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5458 // 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
|
5459 // 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
|
5460 // 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
|
5461 // 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
|
5462 // 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
|
5463 |
0 | 5464 // ---------- rescan dirty cards ------------ |
5465 _timer.reset(); | |
5466 _timer.start(); | |
5467 | |
5468 // 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
|
5469 // (cms_space) in turn. |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5470 // "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
|
5471 do_dirty_card_rescan_tasks(_cms_space, worker_id, &par_mrias_cl); |
0 | 5472 _timer.stop(); |
5473 if (PrintCMSStatistics != 0) { | |
5474 gclog_or_tty->print_cr( | |
5475 "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
|
5476 worker_id, _timer.seconds()); |
0 | 5477 } |
5478 | |
5479 // ---------- steal work from other threads ... | |
5480 // ---------- ... and drain overflow list. | |
5481 _timer.reset(); | |
5482 _timer.start(); | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5483 do_work_steal(worker_id, &par_mrias_cl, _collector->hash_seed(worker_id)); |
0 | 5484 _timer.stop(); |
5485 if (PrintCMSStatistics != 0) { | |
5486 gclog_or_tty->print_cr( | |
5487 "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
|
5488 worker_id, _timer.seconds()); |
0 | 5489 } |
5490 } | |
5491 | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5492 // Note that parameter "i" is not used. |
0 | 5493 void |
11975 | 5494 CMSParMarkTask::do_young_space_rescan(uint worker_id, |
5495 OopsInGenClosure* cl, ContiguousSpace* space, | |
0 | 5496 HeapWord** chunk_array, size_t chunk_top) { |
5497 // Until all tasks completed: | |
5498 // . claim an unclaimed task | |
5499 // . compute region boundaries corresponding to task claimed | |
5500 // using chunk_array | |
5501 // . par_oop_iterate(cl) over that region | |
5502 | |
5503 ResourceMark rm; | |
5504 HandleMark hm; | |
5505 | |
5506 SequentialSubTasksDone* pst = space->par_seq_tasks(); | |
5507 | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5508 uint nth_task = 0; |
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5509 uint n_tasks = pst->n_tasks(); |
0 | 5510 |
12088
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5511 if (n_tasks > 0) { |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5512 assert(pst->valid(), "Uninitialized use?"); |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5513 HeapWord *start, *end; |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5514 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
|
5515 // 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
|
5516 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
|
5517 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
|
5518 start = space->bottom(); |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5519 end = space->top(); |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5520 } else if (nth_task == 0) { |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5521 start = space->bottom(); |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5522 end = chunk_array[nth_task]; |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5523 } else if (nth_task < (uint)chunk_top) { |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5524 assert(nth_task >= 1, "Control point invariant"); |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5525 start = chunk_array[nth_task - 1]; |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5526 end = chunk_array[nth_task]; |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5527 } else { |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5528 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
|
5529 start = chunk_array[chunk_top - 1]; |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5530 end = space->top(); |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5531 } |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5532 MemRegion mr(start, end); |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5533 // Verify that mr is in space |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5534 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
|
5535 "Should be in space"); |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5536 // Verify that "start" is an object boundary |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5537 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
|
5538 "Should be an oop"); |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5539 space->par_oop_iterate(mr, cl); |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5540 } |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5541 pst->all_tasks_completed(); |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5542 } |
0 | 5543 } |
5544 | |
5545 void | |
5546 CMSParRemarkTask::do_dirty_card_rescan_tasks( | |
5547 CompactibleFreeListSpace* sp, int i, | |
5548 Par_MarkRefsIntoAndScanClosure* cl) { | |
5549 // Until all tasks completed: | |
5550 // . claim an unclaimed task | |
5551 // . compute region boundaries corresponding to task claimed | |
5552 // . transfer dirty bits ct->mut for that region | |
5553 // . apply rescanclosure to dirty mut bits for that region | |
5554 | |
5555 ResourceMark rm; | |
5556 HandleMark hm; | |
5557 | |
5558 OopTaskQueue* work_q = work_queue(i); | |
5559 ModUnionClosure modUnionClosure(&(_collector->_modUnionTable)); | |
5560 // CAUTION! CAUTION! CAUTION! CAUTION! CAUTION! CAUTION! CAUTION! | |
5561 // CAUTION: This closure has state that persists across calls to | |
5562 // the work method dirty_range_iterate_clear() in that it has | |
5563 // imbedded in it a (subtype of) UpwardsObjectClosure. The | |
5564 // use of that state in the imbedded UpwardsObjectClosure instance | |
5565 // assumes that the cards are always iterated (even if in parallel | |
5566 // by several threads) in monotonically increasing order per each | |
5567 // thread. This is true of the implementation below which picks | |
5568 // card ranges (chunks) in monotonically increasing order globally | |
5569 // and, a-fortiori, in monotonically increasing order per thread | |
5570 // (the latter order being a subsequence of the former). | |
5571 // If the work code below is ever reorganized into a more chaotic | |
5572 // work-partitioning form than the current "sequential tasks" | |
5573 // paradigm, the use of that persistent state will have to be | |
5574 // revisited and modified appropriately. See also related | |
5575 // bug 4756801 work on which should examine this code to make | |
5576 // sure that the changes there do not run counter to the | |
5577 // assumptions made here and necessary for correctness and | |
5578 // efficiency. Note also that this code might yield inefficient | |
5579 // behaviour in the case of very large objects that span one or | |
5580 // more work chunks. Such objects would potentially be scanned | |
5581 // several times redundantly. Work on 4756801 should try and | |
5582 // address that performance anomaly if at all possible. XXX | |
5583 MemRegion full_span = _collector->_span; | |
5584 CMSBitMap* bm = &(_collector->_markBitMap); // shared | |
5585 MarkFromDirtyCardsClosure | |
5586 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
|
5587 sp, bm, work_q, cl); |
0 | 5588 |
5589 SequentialSubTasksDone* pst = sp->conc_par_seq_tasks(); | |
5590 assert(pst->valid(), "Uninitialized use?"); | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5591 uint nth_task = 0; |
0 | 5592 const int alignment = CardTableModRefBS::card_size * BitsPerWord; |
5593 MemRegion span = sp->used_region(); | |
5594 HeapWord* start_addr = span.start(); | |
5595 HeapWord* end_addr = (HeapWord*)round_to((intptr_t)span.end(), | |
5596 alignment); | |
5597 const size_t chunk_size = sp->rescan_task_size(); // in HeapWord units | |
5598 assert((HeapWord*)round_to((intptr_t)start_addr, alignment) == | |
5599 start_addr, "Check alignment"); | |
5600 assert((size_t)round_to((intptr_t)chunk_size, alignment) == | |
5601 chunk_size, "Check alignment"); | |
5602 | |
5603 while (!pst->is_task_claimed(/* reference */ nth_task)) { | |
5604 // Having claimed the nth_task, compute corresponding mem-region, | |
5605 // which is a-fortiori aligned correctly (i.e. at a MUT bopundary). | |
5606 // The alignment restriction ensures that we do not need any | |
5607 // synchronization with other gang-workers while setting or | |
5608 // clearing bits in thus chunk of the MUT. | |
5609 MemRegion this_span = MemRegion(start_addr + nth_task*chunk_size, | |
5610 start_addr + (nth_task+1)*chunk_size); | |
5611 // The last chunk's end might be way beyond end of the | |
5612 // used region. In that case pull back appropriately. | |
5613 if (this_span.end() > end_addr) { | |
5614 this_span.set_end(end_addr); | |
5615 assert(!this_span.is_empty(), "Program logic (calculation of n_tasks)"); | |
5616 } | |
5617 // Iterate over the dirty cards covering this chunk, marking them | |
5618 // precleaned, and setting the corresponding bits in the mod union | |
5619 // table. Since we have been careful to partition at Card and MUT-word | |
5620 // boundaries no synchronization is needed between parallel threads. | |
5621 _collector->_ct->ct_bs()->dirty_card_iterate(this_span, | |
5622 &modUnionClosure); | |
5623 | |
5624 // Having transferred these marks into the modUnionTable, | |
5625 // rescan the marked objects on the dirty cards in the modUnionTable. | |
5626 // Even if this is at a synchronous collection, the initial marking | |
5627 // may have been done during an asynchronous collection so there | |
5628 // may be dirty bits in the mod-union table. | |
5629 _collector->_modUnionTable.dirty_range_iterate_clear( | |
5630 this_span, &greyRescanClosure); | |
5631 _collector->_modUnionTable.verifyNoOneBitsInRange( | |
5632 this_span.start(), | |
5633 this_span.end()); | |
5634 } | |
5635 pst->all_tasks_completed(); // declare that i am done | |
5636 } | |
5637 | |
5638 // . see if we can share work_queues with ParNew? XXX | |
5639 void | |
5640 CMSParRemarkTask::do_work_steal(int i, Par_MarkRefsIntoAndScanClosure* cl, | |
5641 int* seed) { | |
5642 OopTaskQueue* work_q = work_queue(i); | |
5643 NOT_PRODUCT(int num_steals = 0;) | |
5644 oop obj_to_scan; | |
5645 CMSBitMap* bm = &(_collector->_markBitMap); | |
5646 | |
5647 while (true) { | |
5648 // Completely finish any left over work from (an) earlier round(s) | |
5649 cl->trim_queue(0); | |
679
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
628
diff
changeset
|
5650 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
|
5651 (size_t)ParGCDesiredObjsFromOverflowList); |
0 | 5652 // 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
|
5653 // Passing ParallelGCThreads as the third parameter, no_of_gc_threads, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5654 // 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
|
5655 // 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
|
5656 // pass ParallelGCThreads so this behavior is unchanged. |
0 | 5657 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
|
5658 work_q, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5659 ParallelGCThreads)) { |
0 | 5660 // found something in global overflow list; |
5661 // not yet ready to go stealing work from others. | |
5662 // We'd like to assert(work_q->size() != 0, ...) | |
5663 // because we just took work from the overflow list, | |
5664 // but of course we can't since all of that could have | |
5665 // been already stolen from us. | |
5666 // "He giveth and He taketh away." | |
5667 continue; | |
5668 } | |
5669 // Verify that we have no work before we resort to stealing | |
5670 assert(work_q->size() == 0, "Have work, shouldn't steal"); | |
5671 // Try to steal from other queues that have work | |
5672 if (task_queues()->steal(i, seed, /* reference */ obj_to_scan)) { | |
5673 NOT_PRODUCT(num_steals++;) | |
5674 assert(obj_to_scan->is_oop(), "Oops, not an oop!"); | |
5675 assert(bm->isMarked((HeapWord*)obj_to_scan), "Stole an unmarked oop?"); | |
5676 // Do scanning work | |
5677 obj_to_scan->oop_iterate(cl); | |
5678 // Loop around, finish this work, and try to steal some more | |
5679 } else if (terminator()->offer_termination()) { | |
5680 break; // nirvana from the infinite cycle | |
5681 } | |
5682 } | |
5683 NOT_PRODUCT( | |
5684 if (PrintCMSStatistics != 0) { | |
5685 gclog_or_tty->print("\n\t(%d: stole %d oops)", i, num_steals); | |
5686 } | |
5687 ) | |
5688 assert(work_q->size() == 0 && _collector->overflow_list_is_empty(), | |
5689 "Else our work is not yet done"); | |
5690 } | |
5691 | |
11973
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5692 // 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
|
5693 // 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
|
5694 // 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
|
5695 // 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
|
5696 // 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
|
5697 // preclean phase. |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5698 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
|
5699 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
|
5700 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
|
5701 // 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
|
5702 // 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
|
5703 // address order. |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5704 _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
|
5705 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
|
5706 "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
|
5707 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
|
5708 ((_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
|
5709 (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
|
5710 _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
|
5711 _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
|
5712 } |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5713 _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
|
5714 } |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5715 } |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5716 } |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5717 |
0 | 5718 // Return a thread-local PLAB recording array, as appropriate. |
5719 void* CMSCollector::get_data_recorder(int thr_num) { | |
5720 if (_survivor_plab_array != NULL && | |
5721 (CMSPLABRecordAlways || | |
5722 (_collectorState > Marking && _collectorState < FinalMarking))) { | |
5723 assert(thr_num < (int)ParallelGCThreads, "thr_num is out of bounds"); | |
5724 ChunkArray* ca = &_survivor_plab_array[thr_num]; | |
5725 ca->reset(); // clear it so that fresh data is recorded | |
5726 return (void*) ca; | |
5727 } else { | |
5728 return NULL; | |
5729 } | |
5730 } | |
5731 | |
5732 // Reset all the thread-local PLAB recording arrays | |
5733 void CMSCollector::reset_survivor_plab_arrays() { | |
5734 for (uint i = 0; i < ParallelGCThreads; i++) { | |
5735 _survivor_plab_array[i].reset(); | |
5736 } | |
5737 } | |
5738 | |
5739 // Merge the per-thread plab arrays into the global survivor chunk | |
5740 // array which will provide the partitioning of the survivor space | |
11975 | 5741 // for CMS initial scan and rescan. |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5742 void CMSCollector::merge_survivor_plab_arrays(ContiguousSpace* surv, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5743 int no_of_gc_threads) { |
0 | 5744 assert(_survivor_plab_array != NULL, "Error"); |
5745 assert(_survivor_chunk_array != NULL, "Error"); | |
11975 | 5746 assert(_collectorState == FinalMarking || |
5747 (CMSParallelInitialMarkEnabled && _collectorState == InitialMarking), "Error"); | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5748 for (int j = 0; j < no_of_gc_threads; j++) { |
0 | 5749 _cursor[j] = 0; |
5750 } | |
5751 HeapWord* top = surv->top(); | |
5752 size_t i; | |
5753 for (i = 0; i < _survivor_chunk_capacity; i++) { // all sca entries | |
5754 HeapWord* min_val = top; // Higher than any PLAB address | |
5755 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
|
5756 for (int j = 0; j < no_of_gc_threads; j++) { |
0 | 5757 ChunkArray* cur_sca = &_survivor_plab_array[j]; |
5758 if (_cursor[j] == cur_sca->end()) { | |
5759 continue; | |
5760 } | |
5761 assert(_cursor[j] < cur_sca->end(), "ctl pt invariant"); | |
5762 HeapWord* cur_val = cur_sca->nth(_cursor[j]); | |
5763 assert(surv->used_region().contains(cur_val), "Out of bounds value"); | |
5764 if (cur_val < min_val) { | |
5765 min_tid = j; | |
5766 min_val = cur_val; | |
5767 } else { | |
5768 assert(cur_val < top, "All recorded addresses should be less"); | |
5769 } | |
5770 } | |
5771 // At this point min_val and min_tid are respectively | |
5772 // the least address in _survivor_plab_array[j]->nth(_cursor[j]) | |
5773 // and the thread (j) that witnesses that address. | |
5774 // We record this address in the _survivor_chunk_array[i] | |
5775 // and increment _cursor[min_tid] prior to the next round i. | |
5776 if (min_val == top) { | |
5777 break; | |
5778 } | |
5779 _survivor_chunk_array[i] = min_val; | |
5780 _cursor[min_tid]++; | |
5781 } | |
5782 // We are all done; record the size of the _survivor_chunk_array | |
5783 _survivor_chunk_index = i; // exclusive: [0, i) | |
5784 if (PrintCMSStatistics > 0) { | |
5785 gclog_or_tty->print(" (Survivor:" SIZE_FORMAT "chunks) ", i); | |
5786 } | |
5787 // Verify that we used up all the recorded entries | |
5788 #ifdef ASSERT | |
5789 size_t total = 0; | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5790 for (int j = 0; j < no_of_gc_threads; j++) { |
0 | 5791 assert(_cursor[j] == _survivor_plab_array[j].end(), "Ctl pt invariant"); |
5792 total += _cursor[j]; | |
5793 } | |
5794 assert(total == _survivor_chunk_index, "Ctl Pt Invariant"); | |
5795 // Check that the merged array is in sorted order | |
5796 if (total > 0) { | |
5797 for (size_t i = 0; i < total - 1; i++) { | |
5798 if (PrintCMSStatistics > 0) { | |
5799 gclog_or_tty->print(" (chunk" SIZE_FORMAT ":" INTPTR_FORMAT ") ", | |
5800 i, _survivor_chunk_array[i]); | |
5801 } | |
5802 assert(_survivor_chunk_array[i] < _survivor_chunk_array[i+1], | |
5803 "Not sorted"); | |
5804 } | |
5805 } | |
5806 #endif // ASSERT | |
5807 } | |
5808 | |
5809 // Set up the space's par_seq_tasks structure for work claiming | |
11975 | 5810 // for parallel initial scan and rescan of young gen. |
0 | 5811 // See ParRescanTask where this is currently used. |
5812 void | |
5813 CMSCollector:: | |
5814 initialize_sequential_subtasks_for_young_gen_rescan(int n_threads) { | |
5815 assert(n_threads > 0, "Unexpected n_threads argument"); | |
5816 DefNewGeneration* dng = (DefNewGeneration*)_young_gen; | |
5817 | |
5818 // Eden space | |
12088
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5819 if (!dng->eden()->is_empty()) { |
0 | 5820 SequentialSubTasksDone* pst = dng->eden()->par_seq_tasks(); |
5821 assert(!pst->valid(), "Clobbering existing data?"); | |
5822 // Each valid entry in [0, _eden_chunk_index) represents a task. | |
5823 size_t n_tasks = _eden_chunk_index + 1; | |
5824 assert(n_tasks == 1 || _eden_chunk_array != NULL, "Error"); | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5825 // 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
|
5826 // need to finish in order to be done). |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5827 pst->set_n_threads(n_threads); |
0 | 5828 pst->set_n_tasks((int)n_tasks); |
5829 } | |
5830 | |
5831 // Merge the survivor plab arrays into _survivor_chunk_array | |
5832 if (_survivor_plab_array != NULL) { | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5833 merge_survivor_plab_arrays(dng->from(), n_threads); |
0 | 5834 } else { |
5835 assert(_survivor_chunk_index == 0, "Error"); | |
5836 } | |
5837 | |
5838 // To space | |
5839 { | |
5840 SequentialSubTasksDone* pst = dng->to()->par_seq_tasks(); | |
5841 assert(!pst->valid(), "Clobbering existing data?"); | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5842 // 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
|
5843 // need to finish in order to be done). |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5844 pst->set_n_threads(n_threads); |
0 | 5845 pst->set_n_tasks(1); |
5846 assert(pst->valid(), "Error"); | |
5847 } | |
5848 | |
5849 // From space | |
5850 { | |
5851 SequentialSubTasksDone* pst = dng->from()->par_seq_tasks(); | |
5852 assert(!pst->valid(), "Clobbering existing data?"); | |
5853 size_t n_tasks = _survivor_chunk_index + 1; | |
5854 assert(n_tasks == 1 || _survivor_chunk_array != NULL, "Error"); | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5855 // 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
|
5856 // need to finish in order to be done). |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5857 pst->set_n_threads(n_threads); |
0 | 5858 pst->set_n_tasks((int)n_tasks); |
5859 assert(pst->valid(), "Error"); | |
5860 } | |
5861 } | |
5862 | |
5863 // Parallel version of remark | |
5864 void CMSCollector::do_remark_parallel() { | |
5865 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5866 FlexibleWorkGang* workers = gch->workers(); |
0 | 5867 assert(workers != NULL, "Need parallel worker threads."); |
4095
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5868 // 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
|
5869 // 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
|
5870 // to ParallelGCThreads. |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5871 int n_workers = workers->active_workers(); |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5872 if (n_workers == 0) { |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5873 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
|
5874 n_workers = ParallelGCThreads; |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5875 workers->set_active_workers(n_workers); |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5876 } |
0 | 5877 CompactibleFreeListSpace* cms_space = _cmsGen->cmsSpace(); |
5878 | |
5879 CMSParRemarkTask tsk(this, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5880 cms_space, |
0 | 5881 n_workers, workers, task_queues()); |
5882 | |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5883 // Set up for parallel process_roots work. |
0 | 5884 gch->set_par_threads(n_workers); |
5885 // We won't be iterating over the cards in the card table updating | |
5886 // the younger_gen cards, so we shouldn't call the following else | |
5887 // the verification code as well as subsequent younger_refs_iterate | |
5888 // code would get confused. XXX | |
5889 // gch->rem_set()->prepare_for_younger_refs_iterate(true); // parallel | |
5890 | |
5891 // 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
|
5892 // process_roots (which currently doesn't know how to |
0 | 5893 // parallelize such a scan), but rather will be broken up into |
5894 // a set of parallel tasks (via the sampling that the [abortable] | |
5895 // preclean phase did of EdenSpace, plus the [two] tasks of | |
5896 // scanning the [two] survivor spaces. Further fine-grain | |
5897 // parallelization of the scanning of the survivor spaces | |
5898 // themselves, and of precleaning of the younger gen itself | |
5899 // is deferred to the future. | |
5900 initialize_sequential_subtasks_for_young_gen_rescan(n_workers); | |
5901 | |
5902 // The dirty card rescan work is broken up into a "sequence" | |
5903 // of parallel tasks (per constituent space) that are dynamically | |
5904 // claimed by the parallel threads. | |
5905 cms_space->initialize_sequential_subtasks_for_rescan(n_workers); | |
5906 | |
5907 // It turns out that even when we're using 1 thread, doing the work in a | |
5908 // separate thread causes wide variance in run times. We can't help this | |
5909 // in the multi-threaded case, but we special-case n=1 here to get | |
5910 // repeatable measurements of the 1-thread overhead of the parallel code. | |
5911 if (n_workers > 1) { | |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
5912 // 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
|
5913 // 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
|
5914 // ST marking. |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
5915 ReferenceProcessorMTDiscoveryMutator mt(ref_processor(), true); |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
5916 GenCollectedHeap::StrongRootsScope srs(gch); |
0 | 5917 workers->run_task(&tsk); |
5918 } else { | |
4876
be649fefcdc2
7134655: Crash in reference processing when doing single-threaded remarking
stefank
parents:
4728
diff
changeset
|
5919 ReferenceProcessorMTDiscoveryMutator mt(ref_processor(), false); |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
5920 GenCollectedHeap::StrongRootsScope srs(gch); |
0 | 5921 tsk.work(0); |
5922 } | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5923 |
0 | 5924 gch->set_par_threads(0); // 0 ==> non-parallel. |
5925 // restore, single-threaded for now, any preserved marks | |
5926 // as a result of work_q overflow | |
5927 restore_preserved_marks_if_any(); | |
5928 } | |
5929 | |
5930 // Non-parallel version of remark | |
5931 void CMSCollector::do_remark_non_parallel() { | |
5932 ResourceMark rm; | |
5933 HandleMark hm; | |
5934 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
4876
be649fefcdc2
7134655: Crash in reference processing when doing single-threaded remarking
stefank
parents:
4728
diff
changeset
|
5935 ReferenceProcessorMTDiscoveryMutator mt(ref_processor(), false); |
be649fefcdc2
7134655: Crash in reference processing when doing single-threaded remarking
stefank
parents:
4728
diff
changeset
|
5936 |
0 | 5937 MarkRefsIntoAndScanClosure |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5938 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
|
5939 &_markStack, this, |
0 | 5940 false /* should_yield */, false /* not precleaning */); |
5941 MarkFromDirtyCardsClosure | |
5942 markFromDirtyCardsClosure(this, _span, | |
5943 NULL, // space is set further below | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5944 &_markBitMap, &_markStack, &mrias_cl); |
0 | 5945 { |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
5946 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
|
5947 // 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
|
5948 // mod union table. |
0 | 5949 { |
5950 ModUnionClosure modUnionClosure(&_modUnionTable); | |
5951 _ct->ct_bs()->dirty_card_iterate( | |
5952 _cmsGen->used_region(), | |
5953 &modUnionClosure); | |
5954 } | |
5955 // Having transferred these marks into the modUnionTable, we just need | |
5956 // to rescan the marked objects on the dirty cards in the modUnionTable. | |
5957 // The initial marking may have been done during an asynchronous | |
5958 // collection so there may be dirty bits in the mod-union table. | |
5959 const int alignment = | |
5960 CardTableModRefBS::card_size * BitsPerWord; | |
5961 { | |
5962 // ... First handle dirty cards in CMS gen | |
5963 markFromDirtyCardsClosure.set_space(_cmsGen->cmsSpace()); | |
5964 MemRegion ur = _cmsGen->used_region(); | |
5965 HeapWord* lb = ur.start(); | |
5966 HeapWord* ub = (HeapWord*)round_to((intptr_t)ur.end(), alignment); | |
5967 MemRegion cms_span(lb, ub); | |
5968 _modUnionTable.dirty_range_iterate_clear(cms_span, | |
5969 &markFromDirtyCardsClosure); | |
5970 verify_work_stacks_empty(); | |
5971 if (PrintCMSStatistics != 0) { | |
5972 gclog_or_tty->print(" (re-scanned "SIZE_FORMAT" dirty cards in cms gen) ", | |
5973 markFromDirtyCardsClosure.num_dirty_cards()); | |
5974 } | |
5975 } | |
5976 } | |
5977 if (VerifyDuringGC && | |
5978 GenCollectedHeap::heap()->total_collections() >= VerifyGCStartAt) { | |
5979 HandleMark hm; // Discard invalid handles created during verification | |
6865
4202510ee0fe
8000831: Heap verification output incorrect/incomplete
johnc
parents:
6787
diff
changeset
|
5980 Universe::verify(); |
0 | 5981 } |
5982 { | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
5983 GCTraceTime t("root rescan", PrintGCDetails, false, _gc_timer_cm, _gc_tracer_cm->gc_id()); |
0 | 5984 |
5985 verify_work_stacks_empty(); | |
5986 | |
5987 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
|
5988 GenCollectedHeap::StrongRootsScope srs(gch); |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5989 |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5990 gch->gen_process_roots(_cmsGen->level(), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5991 true, // younger gens as roots |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5992 false, // use the local StrongRootsScope |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5993 SharedHeap::ScanningOption(roots_scanning_options()), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5994 should_unload_classes(), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5995 &mrias_cl, |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5996 NULL, |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5997 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
|
5998 |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
5999 assert(should_unload_classes() |
20254
9fec19bb0659
8032379: Remove the is_scavenging flag to process_strong_roots
mgerdin
parents:
20197
diff
changeset
|
6000 || (roots_scanning_options() & SharedHeap::SO_AllCodeCache), |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
6001 "if we didn't scan the code cache, we have to be ready to drop nmethods with expired weak oops"); |
0 | 6002 } |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6003 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6004 { |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
6005 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
|
6006 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6007 verify_work_stacks_empty(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6008 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6009 // 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
|
6010 // during concurrent marking. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6011 ResourceMark rm; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6012 GrowableArray<ClassLoaderData*>* array = ClassLoaderDataGraph::new_clds(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6013 for (int i = 0; i < array->length(); i++) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6014 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
|
6015 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6016 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6017 // 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
|
6018 ClassLoaderDataGraph::remember_new_clds(false); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6019 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6020 verify_work_stacks_empty(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6021 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6022 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6023 { |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
6024 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
|
6025 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6026 verify_work_stacks_empty(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6027 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6028 RemarkKlassClosure remark_klass_closure(&mrias_cl); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6029 ClassLoaderDataGraph::classes_do(&remark_klass_closure); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6030 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6031 verify_work_stacks_empty(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6032 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6033 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6034 // 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
|
6035 // 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
|
6036 // 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
|
6037 // 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
|
6038 // 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
|
6039 |
0 | 6040 verify_work_stacks_empty(); |
6041 // Restore evacuated mark words, if any, used for overflow list links | |
6042 if (!CMSOverflowEarlyRestoration) { | |
6043 restore_preserved_marks_if_any(); | |
6044 } | |
6045 verify_overflow_empty(); | |
6046 } | |
6047 | |
6048 //////////////////////////////////////////////////////// | |
6049 // Parallel Reference Processing Task Proxy Class | |
6050 //////////////////////////////////////////////////////// | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6051 class CMSRefProcTaskProxy: public AbstractGangTaskWOopQueues { |
0 | 6052 typedef AbstractRefProcTaskExecutor::ProcessTask ProcessTask; |
6053 CMSCollector* _collector; | |
6054 CMSBitMap* _mark_bit_map; | |
143
b5489bb705c9
6662086: 6u4+, 7b11+: CMS never clears referents when -XX:+ParallelRefProcEnabled
ysr
parents:
113
diff
changeset
|
6055 const MemRegion _span; |
0 | 6056 ProcessTask& _task; |
6057 | |
6058 public: | |
6059 CMSRefProcTaskProxy(ProcessTask& task, | |
6060 CMSCollector* collector, | |
6061 const MemRegion& span, | |
6062 CMSBitMap* mark_bit_map, | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6063 AbstractWorkGang* workers, |
0 | 6064 OopTaskQueueSet* task_queues): |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
6065 // 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
|
6066 // 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
|
6067 // the terminator() object. See 6984287. The set_for_termination() |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
6068 // 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
|
6069 AbstractGangTaskWOopQueues("Process referents by policy in parallel", |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6070 task_queues), |
0 | 6071 _task(task), |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6072 _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
|
6073 { |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
6074 assert(_collector->_span.equals(_span) && !_span.is_empty(), |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
6075 "Inconsistency in _span"); |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
6076 set_for_termination(workers->active_workers()); |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
6077 } |
0 | 6078 |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6079 OopTaskQueueSet* task_queues() { return queues(); } |
0 | 6080 |
6081 OopTaskQueue* work_queue(int i) { return task_queues()->queue(i); } | |
6082 | |
6083 void do_work_steal(int i, | |
6084 CMSParDrainMarkingStackClosure* drain, | |
6085 CMSParKeepAliveClosure* keep_alive, | |
6086 int* seed); | |
6087 | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
6088 virtual void work(uint worker_id); |
0 | 6089 }; |
6090 | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
6091 void CMSRefProcTaskProxy::work(uint worker_id) { |
20297
ca8b8e21e2ca
8050973: CMS/G1 GC: add missing Resource and Handle mark
mdoerr
parents:
20278
diff
changeset
|
6092 ResourceMark rm; |
ca8b8e21e2ca
8050973: CMS/G1 GC: add missing Resource and Handle mark
mdoerr
parents:
20278
diff
changeset
|
6093 HandleMark hm; |
143
b5489bb705c9
6662086: 6u4+, 7b11+: CMS never clears referents when -XX:+ParallelRefProcEnabled
ysr
parents:
113
diff
changeset
|
6094 assert(_collector->_span.equals(_span), "Inconsistency in _span"); |
0 | 6095 CMSParKeepAliveClosure par_keep_alive(_collector, _span, |
935 | 6096 _mark_bit_map, |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
6097 work_queue(worker_id)); |
0 | 6098 CMSParDrainMarkingStackClosure par_drain_stack(_collector, _span, |
935 | 6099 _mark_bit_map, |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
6100 work_queue(worker_id)); |
143
b5489bb705c9
6662086: 6u4+, 7b11+: CMS never clears referents when -XX:+ParallelRefProcEnabled
ysr
parents:
113
diff
changeset
|
6101 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
|
6102 _task.work(worker_id, is_alive_closure, par_keep_alive, par_drain_stack); |
0 | 6103 if (_task.marks_oops_alive()) { |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
6104 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
|
6105 _collector->hash_seed(worker_id)); |
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
6106 } |
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
6107 assert(work_queue(worker_id)->size() == 0, "work_queue should be empty"); |
0 | 6108 assert(_collector->_overflow_list == NULL, "non-empty _overflow_list"); |
6109 } | |
6110 | |
6111 class CMSRefEnqueueTaskProxy: public AbstractGangTask { | |
6112 typedef AbstractRefProcTaskExecutor::EnqueueTask EnqueueTask; | |
6113 EnqueueTask& _task; | |
6114 | |
6115 public: | |
6116 CMSRefEnqueueTaskProxy(EnqueueTask& task) | |
6117 : AbstractGangTask("Enqueue reference objects in parallel"), | |
6118 _task(task) | |
6119 { } | |
6120 | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
6121 virtual void work(uint worker_id) |
0 | 6122 { |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
6123 _task.work(worker_id); |
0 | 6124 } |
6125 }; | |
6126 | |
6127 CMSParKeepAliveClosure::CMSParKeepAliveClosure(CMSCollector* collector, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6128 MemRegion span, CMSBitMap* bit_map, OopTaskQueue* work_queue): |
0 | 6129 _span(span), |
6130 _bit_map(bit_map), | |
6131 _work_queue(work_queue), | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6132 _mark_and_push(collector, span, bit_map, work_queue), |
0 | 6133 _low_water_mark(MIN2((uint)(work_queue->max_elems()/4), |
6134 (uint)(CMSWorkQueueDrainThreshold * ParallelGCThreads))) | |
6135 { } | |
6136 | |
6137 // . see if we can share work_queues with ParNew? XXX | |
6138 void CMSRefProcTaskProxy::do_work_steal(int i, | |
6139 CMSParDrainMarkingStackClosure* drain, | |
6140 CMSParKeepAliveClosure* keep_alive, | |
6141 int* seed) { | |
6142 OopTaskQueue* work_q = work_queue(i); | |
6143 NOT_PRODUCT(int num_steals = 0;) | |
6144 oop obj_to_scan; | |
6145 | |
6146 while (true) { | |
6147 // Completely finish any left over work from (an) earlier round(s) | |
6148 drain->trim_queue(0); | |
679
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
628
diff
changeset
|
6149 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
|
6150 (size_t)ParGCDesiredObjsFromOverflowList); |
0 | 6151 // 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
|
6152 // Passing ParallelGCThreads as the third parameter, no_of_gc_threads, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6153 // 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
|
6154 // 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
|
6155 // pass ParallelGCThreads so this behavior is unchanged. |
0 | 6156 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
|
6157 work_q, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6158 ParallelGCThreads)) { |
0 | 6159 // Found something in global overflow list; |
6160 // not yet ready to go stealing work from others. | |
6161 // We'd like to assert(work_q->size() != 0, ...) | |
6162 // because we just took work from the overflow list, | |
6163 // but of course we can't, since all of that might have | |
6164 // been already stolen from us. | |
6165 continue; | |
6166 } | |
6167 // Verify that we have no work before we resort to stealing | |
6168 assert(work_q->size() == 0, "Have work, shouldn't steal"); | |
6169 // Try to steal from other queues that have work | |
6170 if (task_queues()->steal(i, seed, /* reference */ obj_to_scan)) { | |
6171 NOT_PRODUCT(num_steals++;) | |
6172 assert(obj_to_scan->is_oop(), "Oops, not an oop!"); | |
6173 assert(_mark_bit_map->isMarked((HeapWord*)obj_to_scan), "Stole an unmarked oop?"); | |
6174 // Do scanning work | |
6175 obj_to_scan->oop_iterate(keep_alive); | |
6176 // Loop around, finish this work, and try to steal some more | |
6177 } else if (terminator()->offer_termination()) { | |
6178 break; // nirvana from the infinite cycle | |
6179 } | |
6180 } | |
6181 NOT_PRODUCT( | |
6182 if (PrintCMSStatistics != 0) { | |
6183 gclog_or_tty->print("\n\t(%d: stole %d oops)", i, num_steals); | |
6184 } | |
6185 ) | |
6186 } | |
6187 | |
6188 void CMSRefProcTaskExecutor::execute(ProcessTask& task) | |
6189 { | |
6190 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6191 FlexibleWorkGang* workers = gch->workers(); |
0 | 6192 assert(workers != NULL, "Need parallel worker threads."); |
6193 CMSRefProcTaskProxy rp_task(task, &_collector, | |
6194 _collector.ref_processor()->span(), | |
6195 _collector.markBitMap(), | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6196 workers, _collector.task_queues()); |
0 | 6197 workers->run_task(&rp_task); |
6198 } | |
6199 | |
6200 void CMSRefProcTaskExecutor::execute(EnqueueTask& task) | |
6201 { | |
6202 | |
6203 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6204 FlexibleWorkGang* workers = gch->workers(); |
0 | 6205 assert(workers != NULL, "Need parallel worker threads."); |
6206 CMSRefEnqueueTaskProxy enq_task(task); | |
6207 workers->run_task(&enq_task); | |
6208 } | |
6209 | |
6210 void CMSCollector::refProcessingWork(bool asynch, bool clear_all_soft_refs) { | |
6211 | |
6212 ResourceMark rm; | |
6213 HandleMark hm; | |
6214 | |
6215 ReferenceProcessor* rp = ref_processor(); | |
6216 assert(rp->span().equals(_span), "Spans should be equal"); | |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
6217 assert(!rp->enqueuing_is_done(), "Enqueuing should not be complete"); |
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
6218 // Process weak references. |
457
27a80744a83b
6778647: snap(), snap_policy() should be renamed setup(), setup_policy()
ysr
parents:
453
diff
changeset
|
6219 rp->setup_policy(clear_all_soft_refs); |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
6220 verify_work_stacks_empty(); |
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
6221 |
0 | 6222 CMSKeepAliveClosure cmsKeepAliveClosure(this, _span, &_markBitMap, |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6223 &_markStack, false /* !preclean */); |
0 | 6224 CMSDrainMarkingStackClosure cmsDrainMarkingStackClosure(this, |
6225 _span, &_markBitMap, &_markStack, | |
452
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
6226 &cmsKeepAliveClosure, false /* !preclean */); |
0 | 6227 { |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
6228 GCTraceTime t("weak refs processing", PrintGCDetails, false, _gc_timer_cm, _gc_tracer_cm->gc_id()); |
10405 | 6229 |
6230 ReferenceProcessorStats stats; | |
0 | 6231 if (rp->processing_is_mt()) { |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6232 // 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
|
6233 // 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
|
6234 // 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
|
6235 // 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
|
6236 // balance_all_queues() and balance_queues()). |
4095
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
6237 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
6238 int active_workers = ParallelGCThreads; |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
6239 FlexibleWorkGang* workers = gch->workers(); |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
6240 if (workers != NULL) { |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
6241 active_workers = workers->active_workers(); |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
6242 // The expectation is that active_workers will have already |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
6243 // 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
|
6244 // investigate. |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
6245 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
|
6246 } |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
6247 rp->set_active_mt_degree(active_workers); |
0 | 6248 CMSRefProcTaskExecutor task_executor(*this); |
10405 | 6249 stats = rp->process_discovered_references(&_is_alive_closure, |
0 | 6250 &cmsKeepAliveClosure, |
6251 &cmsDrainMarkingStackClosure, | |
10405 | 6252 &task_executor, |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
6253 _gc_timer_cm, |
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
6254 _gc_tracer_cm->gc_id()); |
0 | 6255 } else { |
10405 | 6256 stats = rp->process_discovered_references(&_is_alive_closure, |
0 | 6257 &cmsKeepAliveClosure, |
6258 &cmsDrainMarkingStackClosure, | |
10405 | 6259 NULL, |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
6260 _gc_timer_cm, |
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
6261 _gc_tracer_cm->gc_id()); |
10405 | 6262 } |
6263 _gc_tracer_cm->report_gc_reference_stats(stats); | |
6264 | |
10188
2f50bc369470
8013160: NPG: Remove unnecessary mark stack draining after CodeCache::do_unloading
stefank
parents:
10186
diff
changeset
|
6265 } |
2f50bc369470
8013160: NPG: Remove unnecessary mark stack draining after CodeCache::do_unloading
stefank
parents:
10186
diff
changeset
|
6266 |
2f50bc369470
8013160: NPG: Remove unnecessary mark stack draining after CodeCache::do_unloading
stefank
parents:
10186
diff
changeset
|
6267 // 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
|
6268 verify_work_stacks_empty(); |
0 | 6269 |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
6270 if (should_unload_classes()) { |
0 | 6271 { |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
6272 GCTraceTime t("class unloading", PrintGCDetails, false, _gc_timer_cm, _gc_tracer_cm->gc_id()); |
0 | 6273 |
10188
2f50bc369470
8013160: NPG: Remove unnecessary mark stack draining after CodeCache::do_unloading
stefank
parents:
10186
diff
changeset
|
6274 // Unload classes and purge the SystemDictionary. |
0 | 6275 bool purged_class = SystemDictionary::do_unloading(&_is_alive_closure); |
6276 | |
10188
2f50bc369470
8013160: NPG: Remove unnecessary mark stack draining after CodeCache::do_unloading
stefank
parents:
10186
diff
changeset
|
6277 // Unload nmethods. |
6787
8966c2d65d96
7200470: KeepAliveClosure not needed in CodeCache::do_unloading
brutisso
parents:
6755
diff
changeset
|
6278 CodeCache::do_unloading(&_is_alive_closure, purged_class); |
0 | 6279 |
10188
2f50bc369470
8013160: NPG: Remove unnecessary mark stack draining after CodeCache::do_unloading
stefank
parents:
10186
diff
changeset
|
6280 // 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
|
6281 Klass::clean_weak_klass_links(&_is_alive_closure); |
0 | 6282 } |
6283 | |
6284 { | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
6285 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
|
6286 // Clean up unreferenced symbols in symbol table. |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2147
diff
changeset
|
6287 SymbolTable::unlink(); |
0 | 6288 } |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
6289 |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
6290 { |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
6291 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
|
6292 // Delete entries for dead interned strings. |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
6293 StringTable::unlink(&_is_alive_closure); |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
6294 } |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
6295 } |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
6296 |
2379
b099aaf51bf8
6962931: move interned strings out of the perm gen
jcoomes
parents:
2369
diff
changeset
|
6297 |
0 | 6298 // Restore any preserved marks as a result of mark stack or |
6299 // work queue overflow | |
6300 restore_preserved_marks_if_any(); // done single-threaded for now | |
6301 | |
6302 rp->set_enqueuing_is_done(true); | |
6303 if (rp->processing_is_mt()) { | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6304 rp->balance_all_queues(); |
0 | 6305 CMSRefProcTaskExecutor task_executor(*this); |
6306 rp->enqueue_discovered_references(&task_executor); | |
6307 } else { | |
6308 rp->enqueue_discovered_references(NULL); | |
6309 } | |
6310 rp->verify_no_references_recorded(); | |
6311 assert(!rp->discovery_enabled(), "should have been disabled"); | |
6312 } | |
6313 | |
6314 #ifndef PRODUCT | |
6315 void CMSCollector::check_correct_thread_executing() { | |
6316 Thread* t = Thread::current(); | |
6317 // Only the VM thread or the CMS thread should be here. | |
6318 assert(t->is_ConcurrentGC_thread() || t->is_VM_thread(), | |
6319 "Unexpected thread type"); | |
6320 // If this is the vm thread, the foreground process | |
6321 // should not be waiting. Note that _foregroundGCIsActive is | |
6322 // true while the foreground collector is waiting. | |
6323 if (_foregroundGCShouldWait) { | |
6324 // We cannot be the VM thread | |
6325 assert(t->is_ConcurrentGC_thread(), | |
6326 "Should be CMS thread"); | |
6327 } else { | |
6328 // We can be the CMS thread only if we are in a stop-world | |
6329 // phase of CMS collection. | |
6330 if (t->is_ConcurrentGC_thread()) { | |
6331 assert(_collectorState == InitialMarking || | |
6332 _collectorState == FinalMarking, | |
6333 "Should be a stop-world phase"); | |
6334 // The CMS thread should be holding the CMS_token. | |
6335 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
6336 "Potential interference with concurrently " | |
6337 "executing VM thread"); | |
6338 } | |
6339 } | |
6340 } | |
6341 #endif | |
6342 | |
6343 void CMSCollector::sweep(bool asynch) { | |
6344 assert(_collectorState == Sweeping, "just checking"); | |
6345 check_correct_thread_executing(); | |
6346 verify_work_stacks_empty(); | |
6347 verify_overflow_empty(); | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6348 increment_sweep_count(); |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
3293
diff
changeset
|
6349 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
|
6350 |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6351 _inter_sweep_timer.stop(); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6352 _inter_sweep_estimate.sample(_inter_sweep_timer.seconds()); |
0 | 6353 size_policy()->avg_cms_free_at_sweep()->sample(_cmsGen->free()); |
6354 | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6355 assert(!_intra_sweep_timer.is_active(), "Should not be active"); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6356 _intra_sweep_timer.reset(); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6357 _intra_sweep_timer.start(); |
0 | 6358 if (asynch) { |
6359 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
|
6360 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
|
6361 // First sweep the old gen |
0 | 6362 { |
6363 CMSTokenSyncWithLocks ts(true, _cmsGen->freelistLock(), | |
6364 bitMapLock()); | |
6365 sweepWork(_cmsGen, asynch); | |
6366 } | |
6367 | |
6368 // Update Universe::_heap_*_at_gc figures. | |
6369 // We need all the free list locks to make the abstract state | |
6370 // transition from Sweeping to Resetting. See detailed note | |
6371 // further below. | |
6372 { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6373 CMSTokenSyncWithLocks ts(true, _cmsGen->freelistLock()); |
0 | 6374 // Update heap occupancy information which is used as |
6375 // input to soft ref clearing policy at the next gc. | |
6376 Universe::update_heap_info_at_gc(); | |
6377 _collectorState = Resizing; | |
6378 } | |
6379 } else { | |
6380 // already have needed locks | |
6381 sweepWork(_cmsGen, asynch); | |
6382 // Update heap occupancy information which is used as | |
6383 // input to soft ref clearing policy at the next gc. | |
6384 Universe::update_heap_info_at_gc(); | |
6385 _collectorState = Resizing; | |
6386 } | |
6387 verify_work_stacks_empty(); | |
6388 verify_overflow_empty(); | |
6389 | |
8784
79af1312fc2c
8005602: NPG: classunloading does not happen while CMS GC with -XX:+CMSClassUnloadingEnabled is used
mgerdin
parents:
8740
diff
changeset
|
6390 if (should_unload_classes()) { |
17935
7384f6a12fc1
8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents:
17771
diff
changeset
|
6391 // 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
|
6392 // 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
|
6393 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
|
6394 } |
79af1312fc2c
8005602: NPG: classunloading does not happen while CMS GC with -XX:+CMSClassUnloadingEnabled is used
mgerdin
parents:
8740
diff
changeset
|
6395 |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6396 _intra_sweep_timer.stop(); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6397 _intra_sweep_estimate.sample(_intra_sweep_timer.seconds()); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6398 |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6399 _inter_sweep_timer.reset(); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6400 _inter_sweep_timer.start(); |
0 | 6401 |
4911 | 6402 // We need to use a monotonically non-deccreasing time in ms |
6403 // or we will see time-warp warnings and os::javaTimeMillis() | |
6404 // does not guarantee monotonicity. | |
6405 jlong now = os::javaTimeNanos() / NANOSECS_PER_MILLISEC; | |
6406 update_time_of_last_gc(now); | |
0 | 6407 |
6408 // NOTE on abstract state transitions: | |
6409 // Mutators allocate-live and/or mark the mod-union table dirty | |
6410 // based on the state of the collection. The former is done in | |
6411 // the interval [Marking, Sweeping] and the latter in the interval | |
6412 // [Marking, Sweeping). Thus the transitions into the Marking state | |
6413 // and out of the Sweeping state must be synchronously visible | |
6414 // globally to the mutators. | |
6415 // The transition into the Marking state happens with the world | |
6416 // stopped so the mutators will globally see it. Sweeping is | |
6417 // done asynchronously by the background collector so the transition | |
6418 // from the Sweeping state to the Resizing state must be done | |
6419 // under the freelistLock (as is the check for whether to | |
6420 // allocate-live and whether to dirty the mod-union table). | |
6421 assert(_collectorState == Resizing, "Change of collector state to" | |
6422 " Resizing must be done under the freelistLocks (plural)"); | |
6423 | |
1888
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
6424 // 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
|
6425 // the incremental_collection_failed flag, |
0 | 6426 // thus inviting a younger gen collection to promote into |
6427 // this generation. If such a promotion may still fail, | |
6428 // the flag will be set again when a young collection is | |
6429 // attempted. | |
6430 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
1888
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
6431 gch->clear_incremental_collection_failed(); // Worth retrying as fresh space may have been freed up |
0 | 6432 gch->update_full_collections_completed(_collection_count_start); |
6433 } | |
6434 | |
6435 // FIX ME!!! Looks like this belongs in CFLSpace, with | |
6436 // CMSGen merely delegating to it. | |
6437 void ConcurrentMarkSweepGeneration::setNearLargestChunk() { | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6438 double nearLargestPercent = FLSLargestBlockCoalesceProximity; |
0 | 6439 HeapWord* minAddr = _cmsSpace->bottom(); |
6440 HeapWord* largestAddr = | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
6441 (HeapWord*) _cmsSpace->dictionary()->find_largest_dict(); |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6442 if (largestAddr == NULL) { |
0 | 6443 // The dictionary appears to be empty. In this case |
6444 // try to coalesce at the end of the heap. | |
6445 largestAddr = _cmsSpace->end(); | |
6446 } | |
6447 size_t largestOffset = pointer_delta(largestAddr, minAddr); | |
6448 size_t nearLargestOffset = | |
6449 (size_t)((double)largestOffset * nearLargestPercent) - MinChunkSize; | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6450 if (PrintFLSStatistics != 0) { |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6451 gclog_or_tty->print_cr( |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6452 "CMS: Large Block: " PTR_FORMAT ";" |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6453 " Proximity: " PTR_FORMAT " -> " PTR_FORMAT, |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6454 largestAddr, |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6455 _cmsSpace->nearLargestChunk(), minAddr + nearLargestOffset); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6456 } |
0 | 6457 _cmsSpace->set_nearLargestChunk(minAddr + nearLargestOffset); |
6458 } | |
6459 | |
6460 bool ConcurrentMarkSweepGeneration::isNearLargestChunk(HeapWord* addr) { | |
6461 return addr >= _cmsSpace->nearLargestChunk(); | |
6462 } | |
6463 | |
6464 FreeChunk* ConcurrentMarkSweepGeneration::find_chunk_at_end() { | |
6465 return _cmsSpace->find_chunk_at_end(); | |
6466 } | |
6467 | |
6468 void ConcurrentMarkSweepGeneration::update_gc_stats(int current_level, | |
6469 bool full) { | |
6470 // The next lower level has been collected. Gather any statistics | |
6471 // that are of interest at this point. | |
6472 if (!full && (current_level + 1) == level()) { | |
6473 // Gather statistics on the young generation collection. | |
6474 collector()->stats().record_gc0_end(used()); | |
6475 } | |
6476 } | |
6477 | |
6478 CMSAdaptiveSizePolicy* ConcurrentMarkSweepGeneration::size_policy() { | |
6479 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
6480 assert(gch->kind() == CollectedHeap::GenCollectedHeap, | |
6481 "Wrong type of heap"); | |
6482 CMSAdaptiveSizePolicy* sp = (CMSAdaptiveSizePolicy*) | |
6483 gch->gen_policy()->size_policy(); | |
6484 assert(sp->is_gc_cms_adaptive_size_policy(), | |
6485 "Wrong type of size policy"); | |
6486 return sp; | |
6487 } | |
6488 | |
6489 void ConcurrentMarkSweepGeneration::rotate_debug_collection_type() { | |
6490 if (PrintGCDetails && Verbose) { | |
6491 gclog_or_tty->print("Rotate from %d ", _debug_collection_type); | |
6492 } | |
6493 _debug_collection_type = (CollectionTypes) (_debug_collection_type + 1); | |
6494 _debug_collection_type = | |
6495 (CollectionTypes) (_debug_collection_type % Unknown_collection_type); | |
6496 if (PrintGCDetails && Verbose) { | |
6497 gclog_or_tty->print_cr("to %d ", _debug_collection_type); | |
6498 } | |
6499 } | |
6500 | |
6501 void CMSCollector::sweepWork(ConcurrentMarkSweepGeneration* gen, | |
6502 bool asynch) { | |
6503 // We iterate over the space(s) underlying this generation, | |
6504 // checking the mark bit map to see if the bits corresponding | |
6505 // to specific blocks are marked or not. Blocks that are | |
6506 // marked are live and are not swept up. All remaining blocks | |
6507 // are swept up, with coalescing on-the-fly as we sweep up | |
6508 // contiguous free and/or garbage blocks: | |
6509 // We need to ensure that the sweeper synchronizes with allocators | |
6510 // and stop-the-world collectors. In particular, the following | |
6511 // locks are used: | |
6512 // . CMS token: if this is held, a stop the world collection cannot occur | |
6513 // . freelistLock: if this is held no allocation can occur from this | |
6514 // generation by another thread | |
6515 // . bitMapLock: if this is held, no other thread can access or update | |
6516 // | |
6517 | |
6518 // Note that we need to hold the freelistLock if we use | |
6519 // block iterate below; else the iterator might go awry if | |
6520 // a mutator (or promotion) causes block contents to change | |
6521 // (for instance if the allocator divvies up a block). | |
6522 // If we hold the free list lock, for all practical purposes | |
6523 // young generation GC's can't occur (they'll usually need to | |
6524 // promote), so we might as well prevent all young generation | |
6525 // GC's while we do a sweeping step. For the same reason, we might | |
6526 // as well take the bit map lock for the entire duration | |
6527 | |
6528 // check that we hold the requisite locks | |
6529 assert(have_cms_token(), "Should hold cms token"); | |
6530 assert( (asynch && ConcurrentMarkSweepThread::cms_thread_has_cms_token()) | |
6531 || (!asynch && ConcurrentMarkSweepThread::vm_thread_has_cms_token()), | |
6532 "Should possess CMS token to sweep"); | |
6533 assert_lock_strong(gen->freelistLock()); | |
6534 assert_lock_strong(bitMapLock()); | |
6535 | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6536 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
|
6537 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
|
6538 gen->cmsSpace()->beginSweepFLCensus((float)(_inter_sweep_timer.seconds()), |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6539 _inter_sweep_estimate.padded_average(), |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6540 _intra_sweep_estimate.padded_average()); |
0 | 6541 gen->setNearLargestChunk(); |
6542 | |
6543 { | |
6544 SweepClosure sweepClosure(this, gen, &_markBitMap, | |
6545 CMSYield && asynch); | |
6546 gen->cmsSpace()->blk_iterate_careful(&sweepClosure); | |
6547 // We need to free-up/coalesce garbage/blocks from a | |
6548 // co-terminal free run. This is done in the SweepClosure | |
6549 // destructor; so, do not remove this scope, else the | |
6550 // end-of-sweep-census below will be off by a little bit. | |
6551 } | |
6552 gen->cmsSpace()->sweep_completed(); | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6553 gen->cmsSpace()->endSweepFLCensus(sweep_count()); |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
6554 if (should_unload_classes()) { // unloaded classes this cycle, |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
6555 _concurrent_cycles_since_last_unload = 0; // ... reset count |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
6556 } else { // did not unload classes, |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
6557 _concurrent_cycles_since_last_unload++; // ... increment count |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
6558 } |
0 | 6559 } |
6560 | |
6561 // Reset CMS data structures (for now just the marking bit map) | |
6562 // preparatory for the next cycle. | |
6563 void CMSCollector::reset(bool asynch) { | |
6564 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
6565 CMSAdaptiveSizePolicy* sp = size_policy(); | |
6566 AdaptiveSizePolicyOutput(sp, gch->total_collections()); | |
6567 if (asynch) { | |
6568 CMSTokenSyncWithLocks ts(true, bitMapLock()); | |
6569 | |
6570 // If the state is not "Resetting", the foreground thread | |
6571 // has done a collection and the resetting. | |
6572 if (_collectorState != Resetting) { | |
6573 assert(_collectorState == Idling, "The state should only change" | |
6574 " because the foreground collector has finished the collection"); | |
6575 return; | |
6576 } | |
6577 | |
6578 // Clear the mark bitmap (no grey objects to start with) | |
6579 // for the next cycle. | |
6580 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
|
6581 CMSPhaseAccounting cmspa(this, "reset", _gc_tracer_cm->gc_id(), !PrintGCDetails); |
0 | 6582 |
6583 HeapWord* curAddr = _markBitMap.startWord(); | |
6584 while (curAddr < _markBitMap.endWord()) { | |
6585 size_t remaining = pointer_delta(_markBitMap.endWord(), curAddr); | |
6586 MemRegion chunk(curAddr, MIN2(CMSBitMapYieldQuantum, remaining)); | |
6587 _markBitMap.clear_large_range(chunk); | |
6588 if (ConcurrentMarkSweepThread::should_yield() && | |
6589 !foregroundGCIsActive() && | |
6590 CMSYield) { | |
6591 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
6592 "CMS thread should hold CMS token"); | |
6593 assert_lock_strong(bitMapLock()); | |
6594 bitMapLock()->unlock(); | |
6595 ConcurrentMarkSweepThread::desynchronize(true); | |
6596 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
6597 stopTimer(); | |
6598 if (PrintCMSStatistics != 0) { | |
6599 incrementYields(); | |
6600 } | |
6601 icms_wait(); | |
6602 | |
6603 // See the comment in coordinator_yield() | |
6604 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
|
6605 ConcurrentMarkSweepThread::should_yield() && |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6606 !CMSCollector::foregroundGCIsActive(); ++i) { |
0 | 6607 os::sleep(Thread::current(), 1, false); |
6608 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
6609 } | |
6610 | |
6611 ConcurrentMarkSweepThread::synchronize(true); | |
6612 bitMapLock()->lock_without_safepoint_check(); | |
6613 startTimer(); | |
6614 } | |
6615 curAddr = chunk.end(); | |
6616 } | |
1387
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
6617 // 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
|
6618 // 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
|
6619 // 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
|
6620 // and count. |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
6621 sp->reset_gc_overhead_limit_count(); |
0 | 6622 _collectorState = Idling; |
6623 } else { | |
6624 // already have the lock | |
6625 assert(_collectorState == Resetting, "just checking"); | |
6626 assert_lock_strong(bitMapLock()); | |
6627 _markBitMap.clear_all(); | |
6628 _collectorState = Idling; | |
6629 } | |
6630 | |
6631 // Stop incremental mode after a cycle completes, so that any future cycles | |
6632 // are triggered by allocation. | |
6633 stop_icms(); | |
6634 | |
6635 NOT_PRODUCT( | |
6636 if (RotateCMSCollectionTypes) { | |
6637 _cmsGen->rotate_debug_collection_type(); | |
6638 } | |
6639 ) | |
10405 | 6640 |
6641 register_gc_end(); | |
0 | 6642 } |
6643 | |
6064
9d679effd28c
7166894: Add gc cause to GC logging for all collectors
brutisso
parents:
6028
diff
changeset
|
6644 void CMSCollector::do_CMS_operation(CMS_op_type op, GCCause::Cause gc_cause) { |
0 | 6645 gclog_or_tty->date_stamp(PrintGC && PrintGCDateStamps); |
6646 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
|
6647 GCTraceTime t(GCCauseString("GC", gc_cause), PrintGC, !PrintGCDetails, NULL, _gc_tracer_cm->gc_id()); |
0 | 6648 TraceCollectorStats tcs(counters()); |
6649 | |
6650 switch (op) { | |
6651 case CMS_op_checkpointRootsInitial: { | |
2125
7246a374a9f2
6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents:
1994
diff
changeset
|
6652 SvcGCMarker sgcm(SvcGCMarker::OTHER); |
0 | 6653 checkpointRootsInitial(true); // asynch |
6654 if (PrintGC) { | |
6655 _cmsGen->printOccupancy("initial-mark"); | |
6656 } | |
6657 break; | |
6658 } | |
6659 case CMS_op_checkpointRootsFinal: { | |
2125
7246a374a9f2
6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents:
1994
diff
changeset
|
6660 SvcGCMarker sgcm(SvcGCMarker::OTHER); |
0 | 6661 checkpointRootsFinal(true, // asynch |
6662 false, // !clear_all_soft_refs | |
6663 false); // !init_mark_was_synchronous | |
6664 if (PrintGC) { | |
6665 _cmsGen->printOccupancy("remark"); | |
6666 } | |
6667 break; | |
6668 } | |
6669 default: | |
6670 fatal("No such CMS_op"); | |
6671 } | |
6672 } | |
6673 | |
6674 #ifndef PRODUCT | |
6675 size_t const CMSCollector::skip_header_HeapWords() { | |
6676 return FreeChunk::header_size(); | |
6677 } | |
6678 | |
6679 // Try and collect here conditions that should hold when | |
6680 // CMS thread is exiting. The idea is that the foreground GC | |
6681 // thread should not be blocked if it wants to terminate | |
6682 // the CMS thread and yet continue to run the VM for a while | |
6683 // after that. | |
6684 void CMSCollector::verify_ok_to_terminate() const { | |
6685 assert(Thread::current()->is_ConcurrentGC_thread(), | |
6686 "should be called by CMS thread"); | |
6687 assert(!_foregroundGCShouldWait, "should be false"); | |
6688 // We could check here that all the various low-level locks | |
6689 // are not held by the CMS thread, but that is overkill; see | |
6690 // also CMSThread::verify_ok_to_terminate() where the CGC_lock | |
6691 // is checked. | |
6692 } | |
6693 #endif | |
6694 | |
6695 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
|
6696 assert(_markBitMap.isMarked(addr) && _markBitMap.isMarked(addr + 1), |
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
6697 "missing Printezis mark?"); |
0 | 6698 HeapWord* nextOneAddr = _markBitMap.getNextMarkedWordAddress(addr + 2); |
6699 size_t size = pointer_delta(nextOneAddr + 1, addr); | |
6700 assert(size == CompactibleFreeListSpace::adjustObjectSize(size), | |
6701 "alignment problem"); | |
6702 assert(size >= 3, "Necessary for Printezis marks to work"); | |
6703 return size; | |
6704 } | |
6705 | |
6706 // A variant of the above (block_size_using_printezis_bits()) except | |
6707 // that we return 0 if the P-bits are not yet set. | |
6708 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
|
6709 if (_markBitMap.isMarked(addr + 1)) { |
c5a923563727
6912621: iCMS: Error: assert(_markBitMap.isMarked(addr + 1),"Missing Printezis bit?")
ysr
parents:
2177
diff
changeset
|
6710 assert(_markBitMap.isMarked(addr), "P-bit can be set only for marked objects"); |
0 | 6711 HeapWord* nextOneAddr = _markBitMap.getNextMarkedWordAddress(addr + 2); |
6712 size_t size = pointer_delta(nextOneAddr + 1, addr); | |
6713 assert(size == CompactibleFreeListSpace::adjustObjectSize(size), | |
6714 "alignment problem"); | |
6715 assert(size >= 3, "Necessary for Printezis marks to work"); | |
6716 return size; | |
2226
c5a923563727
6912621: iCMS: Error: assert(_markBitMap.isMarked(addr + 1),"Missing Printezis bit?")
ysr
parents:
2177
diff
changeset
|
6717 } |
c5a923563727
6912621: iCMS: Error: assert(_markBitMap.isMarked(addr + 1),"Missing Printezis bit?")
ysr
parents:
2177
diff
changeset
|
6718 return 0; |
0 | 6719 } |
6720 | |
6721 HeapWord* CMSCollector::next_card_start_after_block(HeapWord* addr) const { | |
6722 size_t sz = 0; | |
6723 oop p = (oop)addr; | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6724 if (p->klass_or_null() != NULL) { |
0 | 6725 sz = CompactibleFreeListSpace::adjustObjectSize(p->size()); |
6726 } else { | |
6727 sz = block_size_using_printezis_bits(addr); | |
6728 } | |
6729 assert(sz > 0, "size must be nonzero"); | |
6730 HeapWord* next_block = addr + sz; | |
6731 HeapWord* next_card = (HeapWord*)round_to((uintptr_t)next_block, | |
6732 CardTableModRefBS::card_size); | |
6733 assert(round_down((uintptr_t)addr, CardTableModRefBS::card_size) < | |
6734 round_down((uintptr_t)next_card, CardTableModRefBS::card_size), | |
6735 "must be different cards"); | |
6736 return next_card; | |
6737 } | |
6738 | |
6739 | |
6740 // CMS Bit Map Wrapper ///////////////////////////////////////// | |
6741 | |
6742 // Construct a CMS bit map infrastructure, but don't create the | |
6743 // bit vector itself. That is done by a separate call CMSBitMap::allocate() | |
6744 // further below. | |
6745 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
|
6746 _bm(), |
0 | 6747 _shifter(shifter), |
6748 _lock(mutex_rank >= 0 ? new Mutex(mutex_rank, mutex_name, true) : NULL) | |
6749 { | |
6750 _bmStartWord = 0; | |
6751 _bmWordSize = 0; | |
6752 } | |
6753 | |
6754 bool CMSBitMap::allocate(MemRegion mr) { | |
6755 _bmStartWord = mr.start(); | |
6756 _bmWordSize = mr.word_size(); | |
6757 ReservedSpace brs(ReservedSpace::allocation_align_size_up( | |
6758 (_bmWordSize >> (_shifter + LogBitsPerByte)) + 1)); | |
6759 if (!brs.is_reserved()) { | |
6760 warning("CMS bit map allocation failure"); | |
6761 return false; | |
6762 } | |
6763 // For now we'll just commit all of the bit map up fromt. | |
6764 // Later on we'll try to be more parsimonious with swap. | |
6765 if (!_virtual_space.initialize(brs, brs.size())) { | |
6766 warning("CMS bit map backing store failure"); | |
6767 return false; | |
6768 } | |
6769 assert(_virtual_space.committed_size() == brs.size(), | |
6770 "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
|
6771 _bm.set_map((BitMap::bm_word_t*)_virtual_space.low()); |
0 | 6772 assert(_virtual_space.committed_size() << (_shifter + LogBitsPerByte) >= |
6773 _bmWordSize, "inconsistency in bit map sizing"); | |
6774 _bm.set_size(_bmWordSize >> _shifter); | |
6775 | |
6776 // bm.clear(); // can we rely on getting zero'd memory? verify below | |
6777 assert(isAllClear(), | |
6778 "Expected zero'd memory from ReservedSpace constructor"); | |
6779 assert(_bm.size() == heapWordDiffToOffsetDiff(sizeInWords()), | |
6780 "consistency check"); | |
6781 return true; | |
6782 } | |
6783 | |
6784 void CMSBitMap::dirty_range_iterate_clear(MemRegion mr, MemRegionClosure* cl) { | |
6785 HeapWord *next_addr, *end_addr, *last_addr; | |
6786 assert_locked(); | |
6787 assert(covers(mr), "out-of-range error"); | |
6788 // XXX assert that start and end are appropriately aligned | |
6789 for (next_addr = mr.start(), end_addr = mr.end(); | |
6790 next_addr < end_addr; next_addr = last_addr) { | |
6791 MemRegion dirty_region = getAndClearMarkedRegion(next_addr, end_addr); | |
6792 last_addr = dirty_region.end(); | |
6793 if (!dirty_region.is_empty()) { | |
6794 cl->do_MemRegion(dirty_region); | |
6795 } else { | |
6796 assert(last_addr == end_addr, "program logic"); | |
6797 return; | |
6798 } | |
6799 } | |
6800 } | |
6801 | |
9076
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
6802 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
|
6803 _bm.print_on_error(st, prefix); |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
6804 } |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
6805 |
0 | 6806 #ifndef PRODUCT |
6807 void CMSBitMap::assert_locked() const { | |
6808 CMSLockVerifier::assert_locked(lock()); | |
6809 } | |
6810 | |
6811 bool CMSBitMap::covers(MemRegion mr) const { | |
6812 // assert(_bm.map() == _virtual_space.low(), "map inconsistency"); | |
6813 assert((size_t)_bm.size() == (_bmWordSize >> _shifter), | |
6814 "size inconsistency"); | |
6815 return (mr.start() >= _bmStartWord) && | |
6816 (mr.end() <= endWord()); | |
6817 } | |
6818 | |
6819 bool CMSBitMap::covers(HeapWord* start, size_t size) const { | |
6820 return (start >= _bmStartWord && (start + size) <= endWord()); | |
6821 } | |
6822 | |
6823 void CMSBitMap::verifyNoOneBitsInRange(HeapWord* left, HeapWord* right) { | |
6824 // verify that there are no 1 bits in the interval [left, right) | |
6825 FalseBitMapClosure falseBitMapClosure; | |
6826 iterate(&falseBitMapClosure, left, right); | |
6827 } | |
6828 | |
6829 void CMSBitMap::region_invariant(MemRegion mr) | |
6830 { | |
6831 assert_locked(); | |
6832 // mr = mr.intersection(MemRegion(_bmStartWord, _bmWordSize)); | |
6833 assert(!mr.is_empty(), "unexpected empty region"); | |
6834 assert(covers(mr), "mr should be covered by bit map"); | |
6835 // convert address range into offset range | |
6836 size_t start_ofs = heapWordToOffset(mr.start()); | |
6837 // Make sure that end() is appropriately aligned | |
6838 assert(mr.end() == (HeapWord*)round_to((intptr_t)mr.end(), | |
6839 (1 << (_shifter+LogHeapWordSize))), | |
6840 "Misaligned mr.end()"); | |
6841 size_t end_ofs = heapWordToOffset(mr.end()); | |
6842 assert(end_ofs > start_ofs, "Should mark at least one bit"); | |
6843 } | |
6844 | |
6845 #endif | |
6846 | |
6847 bool CMSMarkStack::allocate(size_t size) { | |
6848 // allocate a stack of the requisite depth | |
6849 ReservedSpace rs(ReservedSpace::allocation_align_size_up( | |
6850 size * sizeof(oop))); | |
6851 if (!rs.is_reserved()) { | |
6852 warning("CMSMarkStack allocation failure"); | |
6853 return false; | |
6854 } | |
6855 if (!_virtual_space.initialize(rs, rs.size())) { | |
6856 warning("CMSMarkStack backing store failure"); | |
6857 return false; | |
6858 } | |
6859 assert(_virtual_space.committed_size() == rs.size(), | |
6860 "didn't reserve backing store for all of CMS stack?"); | |
6861 _base = (oop*)(_virtual_space.low()); | |
6862 _index = 0; | |
6863 _capacity = size; | |
6864 NOT_PRODUCT(_max_depth = 0); | |
6865 return true; | |
6866 } | |
6867 | |
6868 // XXX FIX ME !!! In the MT case we come in here holding a | |
6869 // leaf lock. For printing we need to take a further lock | |
6870 // which has lower rank. We need to recallibrate the two | |
6871 // lock-ranks involved in order to be able to rpint the | |
6872 // messages below. (Or defer the printing to the caller. | |
6873 // For now we take the expedient path of just disabling the | |
6874 // messages for the problematic case.) | |
6875 void CMSMarkStack::expand() { | |
1284 | 6876 assert(_capacity <= MarkStackSizeMax, "stack bigger than permitted"); |
6877 if (_capacity == MarkStackSizeMax) { | |
0 | 6878 if (_hit_limit++ == 0 && !CMSConcurrentMTEnabled && PrintGCDetails) { |
6879 // We print a warning message only once per CMS cycle. | |
6880 gclog_or_tty->print_cr(" (benign) Hit CMSMarkStack max size limit"); | |
6881 } | |
6882 return; | |
6883 } | |
6884 // Double capacity if possible | |
1284 | 6885 size_t new_capacity = MIN2(_capacity*2, MarkStackSizeMax); |
0 | 6886 // Do not give up existing stack until we have managed to |
6887 // get the double capacity that we desired. | |
6888 ReservedSpace rs(ReservedSpace::allocation_align_size_up( | |
6889 new_capacity * sizeof(oop))); | |
6890 if (rs.is_reserved()) { | |
6891 // Release the backing store associated with old stack | |
6892 _virtual_space.release(); | |
6893 // Reinitialize virtual space for new stack | |
6894 if (!_virtual_space.initialize(rs, rs.size())) { | |
6895 fatal("Not enough swap for expanded marking stack"); | |
6896 } | |
6897 _base = (oop*)(_virtual_space.low()); | |
6898 _index = 0; | |
6899 _capacity = new_capacity; | |
6900 } else if (_failed_double++ == 0 && !CMSConcurrentMTEnabled && PrintGCDetails) { | |
6901 // Failed to double capacity, continue; | |
6902 // we print a detail message only once per CMS cycle. | |
6903 gclog_or_tty->print(" (benign) Failed to expand marking stack from "SIZE_FORMAT"K to " | |
6904 SIZE_FORMAT"K", | |
6905 _capacity / K, new_capacity / K); | |
6906 } | |
6907 } | |
6908 | |
6909 | |
6910 // Closures | |
6911 // XXX: there seems to be a lot of code duplication here; | |
6912 // should refactor and consolidate common code. | |
6913 | |
6914 // This closure is used to mark refs into the CMS generation in | |
6915 // the CMS bit map. Called at the first checkpoint. This closure | |
6916 // 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
|
6917 // generation on which this is used is not an oldest |
0 | 6918 // generation then this will lose younger_gen cards! |
6919 | |
6920 MarkRefsIntoClosure::MarkRefsIntoClosure( | |
994
753cf9794df9
6885169: merge of 4957990 and 6863023 causes conflict on do_nmethods
jrose
parents:
993
diff
changeset
|
6921 MemRegion span, CMSBitMap* bitMap): |
0 | 6922 _span(span), |
994
753cf9794df9
6885169: merge of 4957990 and 6863023 causes conflict on do_nmethods
jrose
parents:
993
diff
changeset
|
6923 _bitMap(bitMap) |
0 | 6924 { |
6925 assert(_ref_processor == NULL, "deliberately left NULL"); | |
6926 assert(_bitMap->covers(_span), "_bitMap/_span mismatch"); | |
6927 } | |
6928 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6929 void MarkRefsIntoClosure::do_oop(oop obj) { |
0 | 6930 // 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
|
6931 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
|
6932 HeapWord* addr = (HeapWord*)obj; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6933 if (_span.contains(addr)) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6934 // 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
|
6935 _bitMap->mark(addr); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6936 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6937 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6938 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6939 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
|
6940 void MarkRefsIntoClosure::do_oop(narrowOop* p) { MarkRefsIntoClosure::do_oop_work(p); } |
0 | 6941 |
11975 | 6942 Par_MarkRefsIntoClosure::Par_MarkRefsIntoClosure( |
6943 MemRegion span, CMSBitMap* bitMap): | |
6944 _span(span), | |
6945 _bitMap(bitMap) | |
6946 { | |
6947 assert(_ref_processor == NULL, "deliberately left NULL"); | |
6948 assert(_bitMap->covers(_span), "_bitMap/_span mismatch"); | |
6949 } | |
6950 | |
6951 void Par_MarkRefsIntoClosure::do_oop(oop obj) { | |
6952 // if p points into _span, then mark corresponding bit in _markBitMap | |
6953 assert(obj->is_oop(), "expected an oop"); | |
6954 HeapWord* addr = (HeapWord*)obj; | |
6955 if (_span.contains(addr)) { | |
6956 // this should be made more efficient | |
6957 _bitMap->par_mark(addr); | |
6958 } | |
6959 } | |
6960 | |
6961 void Par_MarkRefsIntoClosure::do_oop(oop* p) { Par_MarkRefsIntoClosure::do_oop_work(p); } | |
6962 void Par_MarkRefsIntoClosure::do_oop(narrowOop* p) { Par_MarkRefsIntoClosure::do_oop_work(p); } | |
6963 | |
0 | 6964 // A variant of the above, used for CMS marking verification. |
6965 MarkRefsIntoVerifyClosure::MarkRefsIntoVerifyClosure( | |
994
753cf9794df9
6885169: merge of 4957990 and 6863023 causes conflict on do_nmethods
jrose
parents:
993
diff
changeset
|
6966 MemRegion span, CMSBitMap* verification_bm, CMSBitMap* cms_bm): |
0 | 6967 _span(span), |
6968 _verification_bm(verification_bm), | |
994
753cf9794df9
6885169: merge of 4957990 and 6863023 causes conflict on do_nmethods
jrose
parents:
993
diff
changeset
|
6969 _cms_bm(cms_bm) |
753cf9794df9
6885169: merge of 4957990 and 6863023 causes conflict on do_nmethods
jrose
parents:
993
diff
changeset
|
6970 { |
0 | 6971 assert(_ref_processor == NULL, "deliberately left NULL"); |
6972 assert(_verification_bm->covers(_span), "_verification_bm/_span mismatch"); | |
6973 } | |
6974 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6975 void MarkRefsIntoVerifyClosure::do_oop(oop obj) { |
0 | 6976 // 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
|
6977 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
|
6978 HeapWord* addr = (HeapWord*)obj; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6979 if (_span.contains(addr)) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6980 _verification_bm->mark(addr); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6981 if (!_cms_bm->isMarked(addr)) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6982 oop(addr)->print(); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6983 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
|
6984 fatal("... aborting"); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6985 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6986 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6987 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6988 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6989 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
|
6990 void MarkRefsIntoVerifyClosure::do_oop(narrowOop* p) { MarkRefsIntoVerifyClosure::do_oop_work(p); } |
0 | 6991 |
6992 ////////////////////////////////////////////////// | |
6993 // MarkRefsIntoAndScanClosure | |
6994 ////////////////////////////////////////////////// | |
6995 | |
6996 MarkRefsIntoAndScanClosure::MarkRefsIntoAndScanClosure(MemRegion span, | |
6997 ReferenceProcessor* rp, | |
6998 CMSBitMap* bit_map, | |
6999 CMSBitMap* mod_union_table, | |
7000 CMSMarkStack* mark_stack, | |
7001 CMSCollector* collector, | |
7002 bool should_yield, | |
7003 bool concurrent_precleaning): | |
7004 _collector(collector), | |
7005 _span(span), | |
7006 _bit_map(bit_map), | |
7007 _mark_stack(mark_stack), | |
7008 _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
|
7009 mark_stack, concurrent_precleaning), |
0 | 7010 _yield(should_yield), |
7011 _concurrent_precleaning(concurrent_precleaning), | |
7012 _freelistLock(NULL) | |
7013 { | |
7014 _ref_processor = rp; | |
7015 assert(_ref_processor != NULL, "_ref_processor shouldn't be NULL"); | |
7016 } | |
7017 | |
7018 // This closure is used to mark refs into the CMS generation at the | |
7019 // second (final) checkpoint, and to scan and transitively follow | |
7020 // the unmarked oops. It is also used during the concurrent precleaning | |
7021 // phase while scanning objects on dirty cards in the CMS generation. | |
7022 // The marks are made in the marking bit map and the marking stack is | |
7023 // used for keeping the (newly) grey objects during the scan. | |
7024 // 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
|
7025 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
|
7026 if (obj != NULL) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7027 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
|
7028 HeapWord* addr = (HeapWord*)obj; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7029 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
|
7030 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
|
7031 "overflow list should be empty"); |
0 | 7032 if (_span.contains(addr) && |
7033 !_bit_map->isMarked(addr)) { | |
7034 // mark bit map (object is now grey) | |
7035 _bit_map->mark(addr); | |
7036 // push on marking stack (stack should be empty), and drain the | |
7037 // stack by applying this closure to the oops in the oops popped | |
7038 // 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
|
7039 bool res = _mark_stack->push(obj); |
0 | 7040 assert(res, "Should have space to push on empty stack"); |
7041 do { | |
7042 oop new_oop = _mark_stack->pop(); | |
7043 assert(new_oop != NULL && new_oop->is_oop(), "Expected an oop"); | |
7044 assert(_bit_map->isMarked((HeapWord*)new_oop), | |
7045 "only grey objects on this stack"); | |
7046 // iterate over the oops in this oop, marking and pushing | |
7047 // the ones in CMS heap (i.e. in _span). | |
7048 new_oop->oop_iterate(&_pushAndMarkClosure); | |
7049 // check if it's time to yield | |
7050 do_yield_check(); | |
7051 } while (!_mark_stack->isEmpty() || | |
7052 (!_concurrent_precleaning && take_from_overflow_list())); | |
7053 // if marking stack is empty, and we are not doing this | |
7054 // during precleaning, then check the overflow list | |
7055 } | |
7056 assert(_mark_stack->isEmpty(), "post-condition (eager drainage)"); | |
7057 assert(_collector->overflow_list_is_empty(), | |
7058 "overflow list was drained above"); | |
7059 // We could restore evacuated mark words, if any, used for | |
7060 // overflow list links here because the overflow list is | |
7061 // provably empty here. That would reduce the maximum | |
7062 // size requirements for preserved_{oop,mark}_stack. | |
7063 // But we'll just postpone it until we are all done | |
7064 // so we can just stream through. | |
7065 if (!_concurrent_precleaning && CMSOverflowEarlyRestoration) { | |
7066 _collector->restore_preserved_marks_if_any(); | |
7067 assert(_collector->no_preserved_marks(), "No preserved marks"); | |
7068 } | |
7069 assert(!CMSOverflowEarlyRestoration || _collector->no_preserved_marks(), | |
7070 "All preserved marks should have been restored above"); | |
7071 } | |
7072 } | |
7073 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7074 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
|
7075 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
|
7076 |
0 | 7077 void MarkRefsIntoAndScanClosure::do_yield_work() { |
7078 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
7079 "CMS thread should hold CMS token"); | |
7080 assert_lock_strong(_freelistLock); | |
7081 assert_lock_strong(_bit_map->lock()); | |
7082 // relinquish the free_list_lock and bitMaplock() | |
7083 _bit_map->lock()->unlock(); | |
7084 _freelistLock->unlock(); | |
7085 ConcurrentMarkSweepThread::desynchronize(true); | |
7086 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
7087 _collector->stopTimer(); | |
7088 GCPauseTimer p(_collector->size_policy()->concurrent_timer_ptr()); | |
7089 if (PrintCMSStatistics != 0) { | |
7090 _collector->incrementYields(); | |
7091 } | |
7092 _collector->icms_wait(); | |
7093 | |
7094 // 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
|
7095 for (unsigned i = 0; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7096 i < CMSYieldSleepCount && |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7097 ConcurrentMarkSweepThread::should_yield() && |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7098 !CMSCollector::foregroundGCIsActive(); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7099 ++i) { |
0 | 7100 os::sleep(Thread::current(), 1, false); |
7101 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
7102 } | |
7103 | |
7104 ConcurrentMarkSweepThread::synchronize(true); | |
7105 _freelistLock->lock_without_safepoint_check(); | |
7106 _bit_map->lock()->lock_without_safepoint_check(); | |
7107 _collector->startTimer(); | |
7108 } | |
7109 | |
7110 /////////////////////////////////////////////////////////// | |
7111 // Par_MarkRefsIntoAndScanClosure: a parallel version of | |
7112 // MarkRefsIntoAndScanClosure | |
7113 /////////////////////////////////////////////////////////// | |
7114 Par_MarkRefsIntoAndScanClosure::Par_MarkRefsIntoAndScanClosure( | |
7115 CMSCollector* collector, MemRegion span, ReferenceProcessor* rp, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7116 CMSBitMap* bit_map, OopTaskQueue* work_queue): |
0 | 7117 _span(span), |
7118 _bit_map(bit_map), | |
7119 _work_queue(work_queue), | |
7120 _low_water_mark(MIN2((uint)(work_queue->max_elems()/4), | |
7121 (uint)(CMSWorkQueueDrainThreshold * ParallelGCThreads))), | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7122 _par_pushAndMarkClosure(collector, span, rp, bit_map, work_queue) |
0 | 7123 { |
7124 _ref_processor = rp; | |
7125 assert(_ref_processor != NULL, "_ref_processor shouldn't be NULL"); | |
7126 } | |
7127 | |
7128 // This closure is used to mark refs into the CMS generation at the | |
7129 // second (final) checkpoint, and to scan and transitively follow | |
7130 // the unmarked oops. The marks are made in the marking bit map and | |
7131 // the work_queue is used for keeping the (newly) grey objects during | |
7132 // the scan phase whence they are also available for stealing by parallel | |
7133 // threads. Since the marking bit map is shared, updates are | |
7134 // synchronized (via CAS). | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7135 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
|
7136 if (obj != NULL) { |
0 | 7137 // Ignore mark word because this could be an already marked oop |
7138 // 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
|
7139 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
|
7140 HeapWord* addr = (HeapWord*)obj; |
0 | 7141 if (_span.contains(addr) && |
7142 !_bit_map->isMarked(addr)) { | |
7143 // mark bit map (object will become grey): | |
7144 // It is possible for several threads to be | |
7145 // trying to "claim" this object concurrently; | |
7146 // the unique thread that succeeds in marking the | |
7147 // object first will do the subsequent push on | |
7148 // to the work queue (or overflow list). | |
7149 if (_bit_map->par_mark(addr)) { | |
7150 // push on work_queue (which may not be empty), and trim the | |
7151 // queue to an appropriate length by applying this closure to | |
7152 // the oops in the oops popped from the stack (i.e. blacken the | |
7153 // grey objects) | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7154 bool res = _work_queue->push(obj); |
0 | 7155 assert(res, "Low water mark should be less than capacity?"); |
7156 trim_queue(_low_water_mark); | |
7157 } // Else, another thread claimed the object | |
7158 } | |
7159 } | |
7160 } | |
7161 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7162 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
|
7163 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
|
7164 |
0 | 7165 // This closure is used to rescan the marked objects on the dirty cards |
7166 // in the mod union table and the card table proper. | |
7167 size_t ScanMarkedObjectsAgainCarefullyClosure::do_object_careful_m( | |
7168 oop p, MemRegion mr) { | |
7169 | |
7170 size_t size = 0; | |
7171 HeapWord* addr = (HeapWord*)p; | |
7172 DEBUG_ONLY(_collector->verify_work_stacks_empty();) | |
7173 assert(_span.contains(addr), "we are scanning the CMS generation"); | |
7174 // check if it's time to yield | |
7175 if (do_yield_check()) { | |
7176 // We yielded for some foreground stop-world work, | |
7177 // and we have been asked to abort this ongoing preclean cycle. | |
7178 return 0; | |
7179 } | |
7180 if (_bitMap->isMarked(addr)) { | |
7181 // it's marked; is it potentially uninitialized? | |
187 | 7182 if (p->klass_or_null() != NULL) { |
0 | 7183 // an initialized object; ignore mark word in verification below |
7184 // since we are running concurrent with mutators | |
7185 assert(p->is_oop(true), "should be an oop"); | |
7186 if (p->is_objArray()) { | |
7187 // objArrays are precisely marked; restrict scanning | |
7188 // to dirty cards only. | |
187 | 7189 size = CompactibleFreeListSpace::adjustObjectSize( |
7190 p->oop_iterate(_scanningClosure, mr)); | |
0 | 7191 } else { |
7192 // A non-array may have been imprecisely marked; we need | |
7193 // to scan object in its entirety. | |
7194 size = CompactibleFreeListSpace::adjustObjectSize( | |
7195 p->oop_iterate(_scanningClosure)); | |
7196 } | |
9152 | 7197 #ifdef ASSERT |
0 | 7198 size_t direct_size = |
7199 CompactibleFreeListSpace::adjustObjectSize(p->size()); | |
7200 assert(size == direct_size, "Inconsistency in size"); | |
7201 assert(size >= 3, "Necessary for Printezis marks to work"); | |
7202 if (!_bitMap->isMarked(addr+1)) { | |
7203 _bitMap->verifyNoOneBitsInRange(addr+2, addr+size); | |
7204 } else { | |
7205 _bitMap->verifyNoOneBitsInRange(addr+2, addr+size-1); | |
7206 assert(_bitMap->isMarked(addr+size-1), | |
7207 "inconsistent Printezis mark"); | |
7208 } | |
9152 | 7209 #endif // ASSERT |
0 | 7210 } else { |
7211 // an unitialized object | |
7212 assert(_bitMap->isMarked(addr+1), "missing Printezis mark?"); | |
7213 HeapWord* nextOneAddr = _bitMap->getNextMarkedWordAddress(addr + 2); | |
7214 size = pointer_delta(nextOneAddr + 1, addr); | |
7215 assert(size == CompactibleFreeListSpace::adjustObjectSize(size), | |
7216 "alignment problem"); | |
7217 // Note that pre-cleaning needn't redirty the card. OopDesc::set_klass() | |
7218 // will dirty the card when the klass pointer is installed in the | |
7219 // object (signalling the completion of initialization). | |
7220 } | |
7221 } else { | |
7222 // 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
|
7223 if (p->klass_or_null() == NULL) { |
0 | 7224 // An uninitialized object, skip to the next card, since |
7225 // we may not be able to read its P-bits yet. | |
7226 assert(size == 0, "Initial value"); | |
7227 } else { | |
7228 // An object not (yet) reached by marking: we merely need to | |
7229 // compute its size so as to go look at the next block. | |
7230 assert(p->is_oop(true), "should be an oop"); | |
7231 size = CompactibleFreeListSpace::adjustObjectSize(p->size()); | |
7232 } | |
7233 } | |
7234 DEBUG_ONLY(_collector->verify_work_stacks_empty();) | |
7235 return size; | |
7236 } | |
7237 | |
7238 void ScanMarkedObjectsAgainCarefullyClosure::do_yield_work() { | |
7239 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
7240 "CMS thread should hold CMS token"); | |
7241 assert_lock_strong(_freelistLock); | |
7242 assert_lock_strong(_bitMap->lock()); | |
7243 // relinquish the free_list_lock and bitMaplock() | |
7244 _bitMap->lock()->unlock(); | |
7245 _freelistLock->unlock(); | |
7246 ConcurrentMarkSweepThread::desynchronize(true); | |
7247 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
7248 _collector->stopTimer(); | |
7249 GCPauseTimer p(_collector->size_policy()->concurrent_timer_ptr()); | |
7250 if (PrintCMSStatistics != 0) { | |
7251 _collector->incrementYields(); | |
7252 } | |
7253 _collector->icms_wait(); | |
7254 | |
7255 // See the comment in coordinator_yield() | |
7256 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
|
7257 ConcurrentMarkSweepThread::should_yield() && |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7258 !CMSCollector::foregroundGCIsActive(); ++i) { |
0 | 7259 os::sleep(Thread::current(), 1, false); |
7260 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
7261 } | |
7262 | |
7263 ConcurrentMarkSweepThread::synchronize(true); | |
7264 _freelistLock->lock_without_safepoint_check(); | |
7265 _bitMap->lock()->lock_without_safepoint_check(); | |
7266 _collector->startTimer(); | |
7267 } | |
7268 | |
7269 | |
7270 ////////////////////////////////////////////////////////////////// | |
7271 // SurvivorSpacePrecleanClosure | |
7272 ////////////////////////////////////////////////////////////////// | |
7273 // This (single-threaded) closure is used to preclean the oops in | |
7274 // the survivor spaces. | |
7275 size_t SurvivorSpacePrecleanClosure::do_object_careful(oop p) { | |
7276 | |
7277 HeapWord* addr = (HeapWord*)p; | |
7278 DEBUG_ONLY(_collector->verify_work_stacks_empty();) | |
7279 assert(!_span.contains(addr), "we are scanning the survivor spaces"); | |
187 | 7280 assert(p->klass_or_null() != NULL, "object should be initializd"); |
0 | 7281 // an initialized object; ignore mark word in verification below |
7282 // since we are running concurrent with mutators | |
7283 assert(p->is_oop(true), "should be an oop"); | |
7284 // Note that we do not yield while we iterate over | |
7285 // the interior oops of p, pushing the relevant ones | |
7286 // on our marking stack. | |
7287 size_t size = p->oop_iterate(_scanning_closure); | |
7288 do_yield_check(); | |
7289 // Observe that below, we do not abandon the preclean | |
7290 // phase as soon as we should; rather we empty the | |
7291 // marking stack before returning. This is to satisfy | |
7292 // some existing assertions. In general, it may be a | |
7293 // good idea to abort immediately and complete the marking | |
7294 // from the grey objects at a later time. | |
7295 while (!_mark_stack->isEmpty()) { | |
7296 oop new_oop = _mark_stack->pop(); | |
7297 assert(new_oop != NULL && new_oop->is_oop(), "Expected an oop"); | |
7298 assert(_bit_map->isMarked((HeapWord*)new_oop), | |
7299 "only grey objects on this stack"); | |
7300 // iterate over the oops in this oop, marking and pushing | |
7301 // the ones in CMS heap (i.e. in _span). | |
7302 new_oop->oop_iterate(_scanning_closure); | |
7303 // check if it's time to yield | |
7304 do_yield_check(); | |
7305 } | |
7306 unsigned int after_count = | |
7307 GenCollectedHeap::heap()->total_collections(); | |
7308 bool abort = (_before_count != after_count) || | |
7309 _collector->should_abort_preclean(); | |
7310 return abort ? 0 : size; | |
7311 } | |
7312 | |
7313 void SurvivorSpacePrecleanClosure::do_yield_work() { | |
7314 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
7315 "CMS thread should hold CMS token"); | |
7316 assert_lock_strong(_bit_map->lock()); | |
7317 // Relinquish the bit map lock | |
7318 _bit_map->lock()->unlock(); | |
7319 ConcurrentMarkSweepThread::desynchronize(true); | |
7320 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
7321 _collector->stopTimer(); | |
7322 GCPauseTimer p(_collector->size_policy()->concurrent_timer_ptr()); | |
7323 if (PrintCMSStatistics != 0) { | |
7324 _collector->incrementYields(); | |
7325 } | |
7326 _collector->icms_wait(); | |
7327 | |
7328 // See the comment in coordinator_yield() | |
7329 for (unsigned i = 0; i < CMSYieldSleepCount && | |
7330 ConcurrentMarkSweepThread::should_yield() && | |
7331 !CMSCollector::foregroundGCIsActive(); ++i) { | |
7332 os::sleep(Thread::current(), 1, false); | |
7333 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
7334 } | |
7335 | |
7336 ConcurrentMarkSweepThread::synchronize(true); | |
7337 _bit_map->lock()->lock_without_safepoint_check(); | |
7338 _collector->startTimer(); | |
7339 } | |
7340 | |
7341 // This closure is used to rescan the marked objects on the dirty cards | |
7342 // in the mod union table and the card table proper. In the parallel | |
7343 // case, although the bitMap is shared, we do a single read so the | |
7344 // isMarked() query is "safe". | |
7345 bool ScanMarkedObjectsAgainClosure::do_object_bm(oop p, MemRegion mr) { | |
7346 // Ignore mark word because we are running concurrent with mutators | |
7347 assert(p->is_oop_or_null(true), "expected an oop or null"); | |
7348 HeapWord* addr = (HeapWord*)p; | |
7349 assert(_span.contains(addr), "we are scanning the CMS generation"); | |
7350 bool is_obj_array = false; | |
9152 | 7351 #ifdef ASSERT |
0 | 7352 if (!_parallel) { |
7353 assert(_mark_stack->isEmpty(), "pre-condition (eager drainage)"); | |
7354 assert(_collector->overflow_list_is_empty(), | |
7355 "overflow list should be empty"); | |
7356 | |
7357 } | |
9152 | 7358 #endif // ASSERT |
0 | 7359 if (_bit_map->isMarked(addr)) { |
7360 // Obj arrays are precisely marked, non-arrays are not; | |
7361 // so we scan objArrays precisely and non-arrays in their | |
7362 // entirety. | |
7363 if (p->is_objArray()) { | |
7364 is_obj_array = true; | |
7365 if (_parallel) { | |
7366 p->oop_iterate(_par_scan_closure, mr); | |
7367 } else { | |
7368 p->oop_iterate(_scan_closure, mr); | |
7369 } | |
7370 } else { | |
7371 if (_parallel) { | |
7372 p->oop_iterate(_par_scan_closure); | |
7373 } else { | |
7374 p->oop_iterate(_scan_closure); | |
7375 } | |
7376 } | |
7377 } | |
9152 | 7378 #ifdef ASSERT |
0 | 7379 if (!_parallel) { |
7380 assert(_mark_stack->isEmpty(), "post-condition (eager drainage)"); | |
7381 assert(_collector->overflow_list_is_empty(), | |
7382 "overflow list should be empty"); | |
7383 | |
7384 } | |
9152 | 7385 #endif // ASSERT |
0 | 7386 return is_obj_array; |
7387 } | |
7388 | |
7389 MarkFromRootsClosure::MarkFromRootsClosure(CMSCollector* collector, | |
7390 MemRegion span, | |
7391 CMSBitMap* bitMap, CMSMarkStack* markStack, | |
7392 bool should_yield, bool verifying): | |
7393 _collector(collector), | |
7394 _span(span), | |
7395 _bitMap(bitMap), | |
7396 _mut(&collector->_modUnionTable), | |
7397 _markStack(markStack), | |
7398 _yield(should_yield), | |
7399 _skipBits(0) | |
7400 { | |
7401 assert(_markStack->isEmpty(), "stack should be empty"); | |
7402 _finger = _bitMap->startWord(); | |
7403 _threshold = _finger; | |
7404 assert(_collector->_restart_addr == NULL, "Sanity check"); | |
7405 assert(_span.contains(_finger), "Out of bounds _finger?"); | |
7406 DEBUG_ONLY(_verifying = verifying;) | |
7407 } | |
7408 | |
7409 void MarkFromRootsClosure::reset(HeapWord* addr) { | |
7410 assert(_markStack->isEmpty(), "would cause duplicates on stack"); | |
7411 assert(_span.contains(addr), "Out of bounds _finger?"); | |
7412 _finger = addr; | |
7413 _threshold = (HeapWord*)round_to( | |
7414 (intptr_t)_finger, CardTableModRefBS::card_size); | |
7415 } | |
7416 | |
7417 // Should revisit to see if this should be restructured for | |
7418 // greater efficiency. | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7419 bool MarkFromRootsClosure::do_bit(size_t offset) { |
0 | 7420 if (_skipBits > 0) { |
7421 _skipBits--; | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7422 return true; |
0 | 7423 } |
7424 // convert offset into a HeapWord* | |
7425 HeapWord* addr = _bitMap->startWord() + offset; | |
7426 assert(_bitMap->endWord() && addr < _bitMap->endWord(), | |
7427 "address out of range"); | |
7428 assert(_bitMap->isMarked(addr), "tautology"); | |
7429 if (_bitMap->isMarked(addr+1)) { | |
7430 // this is an allocated but not yet initialized object | |
7431 assert(_skipBits == 0, "tautology"); | |
7432 _skipBits = 2; // skip next two marked bits ("Printezis-marks") | |
7433 oop p = oop(addr); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7434 if (p->klass_or_null() == NULL) { |
0 | 7435 DEBUG_ONLY(if (!_verifying) {) |
7436 // We re-dirty the cards on which this object lies and increase | |
7437 // the _threshold so that we'll come back to scan this object | |
7438 // during the preclean or remark phase. (CMSCleanOnEnter) | |
7439 if (CMSCleanOnEnter) { | |
7440 size_t sz = _collector->block_size_using_printezis_bits(addr); | |
7441 HeapWord* end_card_addr = (HeapWord*)round_to( | |
7442 (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
|
7443 MemRegion redirty_range = MemRegion(addr, end_card_addr); |
0 | 7444 assert(!redirty_range.is_empty(), "Arithmetical tautology"); |
7445 // Bump _threshold to end_card_addr; note that | |
7446 // _threshold cannot possibly exceed end_card_addr, anyhow. | |
7447 // This prevents future clearing of the card as the scan proceeds | |
7448 // to the right. | |
7449 assert(_threshold <= end_card_addr, | |
7450 "Because we are just scanning into this object"); | |
7451 if (_threshold < end_card_addr) { | |
7452 _threshold = end_card_addr; | |
7453 } | |
187 | 7454 if (p->klass_or_null() != NULL) { |
0 | 7455 // Redirty the range of cards... |
7456 _mut->mark_range(redirty_range); | |
7457 } // ...else the setting of klass will dirty the card anyway. | |
7458 } | |
7459 DEBUG_ONLY(}) | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7460 return true; |
0 | 7461 } |
7462 } | |
7463 scanOopsInOop(addr); | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7464 return true; |
0 | 7465 } |
7466 | |
7467 // We take a break if we've been at this for a while, | |
7468 // so as to avoid monopolizing the locks involved. | |
7469 void MarkFromRootsClosure::do_yield_work() { | |
7470 // First give up the locks, then yield, then re-lock | |
7471 // We should probably use a constructor/destructor idiom to | |
7472 // do this unlock/lock or modify the MutexUnlocker class to | |
7473 // serve our purpose. XXX | |
7474 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
7475 "CMS thread should hold CMS token"); | |
7476 assert_lock_strong(_bitMap->lock()); | |
7477 _bitMap->lock()->unlock(); | |
7478 ConcurrentMarkSweepThread::desynchronize(true); | |
7479 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
7480 _collector->stopTimer(); | |
7481 GCPauseTimer p(_collector->size_policy()->concurrent_timer_ptr()); | |
7482 if (PrintCMSStatistics != 0) { | |
7483 _collector->incrementYields(); | |
7484 } | |
7485 _collector->icms_wait(); | |
7486 | |
7487 // See the comment in coordinator_yield() | |
7488 for (unsigned i = 0; i < CMSYieldSleepCount && | |
7489 ConcurrentMarkSweepThread::should_yield() && | |
7490 !CMSCollector::foregroundGCIsActive(); ++i) { | |
7491 os::sleep(Thread::current(), 1, false); | |
7492 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
7493 } | |
7494 | |
7495 ConcurrentMarkSweepThread::synchronize(true); | |
7496 _bitMap->lock()->lock_without_safepoint_check(); | |
7497 _collector->startTimer(); | |
7498 } | |
7499 | |
7500 void MarkFromRootsClosure::scanOopsInOop(HeapWord* ptr) { | |
7501 assert(_bitMap->isMarked(ptr), "expected bit to be set"); | |
7502 assert(_markStack->isEmpty(), | |
7503 "should drain stack to limit stack usage"); | |
7504 // 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
|
7505 oop obj = oop(ptr); |
0 | 7506 // Ignore mark word in verification below, since we |
7507 // 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
|
7508 assert(obj->is_oop(true), "should be an oop"); |
0 | 7509 assert(_finger <= ptr, "_finger runneth ahead"); |
7510 // 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
|
7511 _finger = ptr + obj->size(); |
0 | 7512 assert(_finger > ptr, "we just incremented it above"); |
7513 // On large heaps, it may take us some time to get through | |
7514 // the marking phase (especially if running iCMS). During | |
7515 // this time it's possible that a lot of mutations have | |
7516 // accumulated in the card table and the mod union table -- | |
7517 // these mutation records are redundant until we have | |
7518 // actually traced into the corresponding card. | |
7519 // Here, we check whether advancing the finger would make | |
7520 // us cross into a new card, and if so clear corresponding | |
7521 // cards in the MUT (preclean them in the card-table in the | |
7522 // future). | |
7523 | |
7524 DEBUG_ONLY(if (!_verifying) {) | |
7525 // The clean-on-enter optimization is disabled by default, | |
7526 // until we fix 6178663. | |
7527 if (CMSCleanOnEnter && (_finger > _threshold)) { | |
7528 // [_threshold, _finger) represents the interval | |
7529 // of cards to be cleared in MUT (or precleaned in card table). | |
7530 // The set of cards to be cleared is all those that overlap | |
7531 // with the interval [_threshold, _finger); note that | |
7532 // _threshold is always kept card-aligned but _finger isn't | |
7533 // always card-aligned. | |
7534 HeapWord* old_threshold = _threshold; | |
7535 assert(old_threshold == (HeapWord*)round_to( | |
7536 (intptr_t)old_threshold, CardTableModRefBS::card_size), | |
7537 "_threshold should always be card-aligned"); | |
7538 _threshold = (HeapWord*)round_to( | |
7539 (intptr_t)_finger, CardTableModRefBS::card_size); | |
7540 MemRegion mr(old_threshold, _threshold); | |
7541 assert(!mr.is_empty(), "Control point invariant"); | |
7542 assert(_span.contains(mr), "Should clear within span"); | |
7543 _mut->clear_range(mr); | |
7544 } | |
7545 DEBUG_ONLY(}) | |
7546 // Note: the finger doesn't advance while we drain | |
7547 // the stack below. | |
7548 PushOrMarkClosure pushOrMarkClosure(_collector, | |
7549 _span, _bitMap, _markStack, | |
7550 _finger, this); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7551 bool res = _markStack->push(obj); |
0 | 7552 assert(res, "Empty non-zero size stack should have space for single push"); |
7553 while (!_markStack->isEmpty()) { | |
7554 oop new_oop = _markStack->pop(); | |
7555 // Skip verifying header mark word below because we are | |
7556 // running concurrent with mutators. | |
7557 assert(new_oop->is_oop(true), "Oops! expected to pop an oop"); | |
7558 // now scan this oop's oops | |
7559 new_oop->oop_iterate(&pushOrMarkClosure); | |
7560 do_yield_check(); | |
7561 } | |
7562 assert(_markStack->isEmpty(), "tautology, emphasizing post-condition"); | |
7563 } | |
7564 | |
7565 Par_MarkFromRootsClosure::Par_MarkFromRootsClosure(CMSConcMarkingTask* task, | |
7566 CMSCollector* collector, MemRegion span, | |
7567 CMSBitMap* bit_map, | |
7568 OopTaskQueue* work_queue, | |
7569 CMSMarkStack* overflow_stack, | |
7570 bool should_yield): | |
7571 _collector(collector), | |
7572 _whole_span(collector->_span), | |
7573 _span(span), | |
7574 _bit_map(bit_map), | |
7575 _mut(&collector->_modUnionTable), | |
7576 _work_queue(work_queue), | |
7577 _overflow_stack(overflow_stack), | |
7578 _yield(should_yield), | |
7579 _skip_bits(0), | |
7580 _task(task) | |
7581 { | |
7582 assert(_work_queue->size() == 0, "work_queue should be empty"); | |
7583 _finger = span.start(); | |
7584 _threshold = _finger; // XXX Defer clear-on-enter optimization for now | |
7585 assert(_span.contains(_finger), "Out of bounds _finger?"); | |
7586 } | |
7587 | |
7588 // Should revisit to see if this should be restructured for | |
7589 // greater efficiency. | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7590 bool Par_MarkFromRootsClosure::do_bit(size_t offset) { |
0 | 7591 if (_skip_bits > 0) { |
7592 _skip_bits--; | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7593 return true; |
0 | 7594 } |
7595 // convert offset into a HeapWord* | |
7596 HeapWord* addr = _bit_map->startWord() + offset; | |
7597 assert(_bit_map->endWord() && addr < _bit_map->endWord(), | |
7598 "address out of range"); | |
7599 assert(_bit_map->isMarked(addr), "tautology"); | |
7600 if (_bit_map->isMarked(addr+1)) { | |
7601 // this is an allocated object that might not yet be initialized | |
7602 assert(_skip_bits == 0, "tautology"); | |
7603 _skip_bits = 2; // skip next two marked bits ("Printezis-marks") | |
7604 oop p = oop(addr); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7605 if (p->klass_or_null() == NULL) { |
0 | 7606 // in the case of Clean-on-Enter optimization, redirty card |
7607 // and avoid clearing card by increasing the threshold. | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7608 return true; |
0 | 7609 } |
7610 } | |
7611 scan_oops_in_oop(addr); | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7612 return true; |
0 | 7613 } |
7614 | |
7615 void Par_MarkFromRootsClosure::scan_oops_in_oop(HeapWord* ptr) { | |
7616 assert(_bit_map->isMarked(ptr), "expected bit to be set"); | |
7617 // Should we assert that our work queue is empty or | |
7618 // below some drain limit? | |
7619 assert(_work_queue->size() == 0, | |
7620 "should drain stack to limit stack usage"); | |
7621 // 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
|
7622 oop obj = oop(ptr); |
0 | 7623 // Ignore mark word in verification below, since we |
7624 // 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
|
7625 assert(obj->is_oop(true), "should be an oop"); |
0 | 7626 assert(_finger <= ptr, "_finger runneth ahead"); |
7627 // 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
|
7628 _finger = ptr + obj->size(); |
0 | 7629 assert(_finger > ptr, "we just incremented it above"); |
7630 // On large heaps, it may take us some time to get through | |
7631 // the marking phase (especially if running iCMS). During | |
7632 // this time it's possible that a lot of mutations have | |
7633 // accumulated in the card table and the mod union table -- | |
7634 // these mutation records are redundant until we have | |
7635 // actually traced into the corresponding card. | |
7636 // Here, we check whether advancing the finger would make | |
7637 // us cross into a new card, and if so clear corresponding | |
7638 // cards in the MUT (preclean them in the card-table in the | |
7639 // future). | |
7640 | |
7641 // The clean-on-enter optimization is disabled by default, | |
7642 // until we fix 6178663. | |
7643 if (CMSCleanOnEnter && (_finger > _threshold)) { | |
7644 // [_threshold, _finger) represents the interval | |
7645 // of cards to be cleared in MUT (or precleaned in card table). | |
7646 // The set of cards to be cleared is all those that overlap | |
7647 // with the interval [_threshold, _finger); note that | |
7648 // _threshold is always kept card-aligned but _finger isn't | |
7649 // always card-aligned. | |
7650 HeapWord* old_threshold = _threshold; | |
7651 assert(old_threshold == (HeapWord*)round_to( | |
7652 (intptr_t)old_threshold, CardTableModRefBS::card_size), | |
7653 "_threshold should always be card-aligned"); | |
7654 _threshold = (HeapWord*)round_to( | |
7655 (intptr_t)_finger, CardTableModRefBS::card_size); | |
7656 MemRegion mr(old_threshold, _threshold); | |
7657 assert(!mr.is_empty(), "Control point invariant"); | |
7658 assert(_span.contains(mr), "Should clear within span"); // _whole_span ?? | |
7659 _mut->clear_range(mr); | |
7660 } | |
7661 | |
7662 // Note: the local finger doesn't advance while we drain | |
7663 // the stack below, but the global finger sure can and will. | |
7664 HeapWord** gfa = _task->global_finger_addr(); | |
7665 Par_PushOrMarkClosure pushOrMarkClosure(_collector, | |
7666 _span, _bit_map, | |
7667 _work_queue, | |
7668 _overflow_stack, | |
7669 _finger, | |
7670 gfa, this); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7671 bool res = _work_queue->push(obj); // overflow could occur here |
0 | 7672 assert(res, "Will hold once we use workqueues"); |
7673 while (true) { | |
7674 oop new_oop; | |
7675 if (!_work_queue->pop_local(new_oop)) { | |
7676 // We emptied our work_queue; check if there's stuff that can | |
7677 // be gotten from the overflow stack. | |
7678 if (CMSConcMarkingTask::get_work_from_overflow_stack( | |
7679 _overflow_stack, _work_queue)) { | |
7680 do_yield_check(); | |
7681 continue; | |
7682 } else { // done | |
7683 break; | |
7684 } | |
7685 } | |
7686 // Skip verifying header mark word below because we are | |
7687 // running concurrent with mutators. | |
7688 assert(new_oop->is_oop(true), "Oops! expected to pop an oop"); | |
7689 // now scan this oop's oops | |
7690 new_oop->oop_iterate(&pushOrMarkClosure); | |
7691 do_yield_check(); | |
7692 } | |
7693 assert(_work_queue->size() == 0, "tautology, emphasizing post-condition"); | |
7694 } | |
7695 | |
7696 // Yield in response to a request from VM Thread or | |
7697 // from mutators. | |
7698 void Par_MarkFromRootsClosure::do_yield_work() { | |
7699 assert(_task != NULL, "sanity"); | |
7700 _task->yield(); | |
7701 } | |
7702 | |
7703 // A variant of the above used for verifying CMS marking work. | |
7704 MarkFromRootsVerifyClosure::MarkFromRootsVerifyClosure(CMSCollector* collector, | |
7705 MemRegion span, | |
7706 CMSBitMap* verification_bm, CMSBitMap* cms_bm, | |
7707 CMSMarkStack* mark_stack): | |
7708 _collector(collector), | |
7709 _span(span), | |
7710 _verification_bm(verification_bm), | |
7711 _cms_bm(cms_bm), | |
7712 _mark_stack(mark_stack), | |
7713 _pam_verify_closure(collector, span, verification_bm, cms_bm, | |
7714 mark_stack) | |
7715 { | |
7716 assert(_mark_stack->isEmpty(), "stack should be empty"); | |
7717 _finger = _verification_bm->startWord(); | |
7718 assert(_collector->_restart_addr == NULL, "Sanity check"); | |
7719 assert(_span.contains(_finger), "Out of bounds _finger?"); | |
7720 } | |
7721 | |
7722 void MarkFromRootsVerifyClosure::reset(HeapWord* addr) { | |
7723 assert(_mark_stack->isEmpty(), "would cause duplicates on stack"); | |
7724 assert(_span.contains(addr), "Out of bounds _finger?"); | |
7725 _finger = addr; | |
7726 } | |
7727 | |
7728 // Should revisit to see if this should be restructured for | |
7729 // greater efficiency. | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7730 bool MarkFromRootsVerifyClosure::do_bit(size_t offset) { |
0 | 7731 // convert offset into a HeapWord* |
7732 HeapWord* addr = _verification_bm->startWord() + offset; | |
7733 assert(_verification_bm->endWord() && addr < _verification_bm->endWord(), | |
7734 "address out of range"); | |
7735 assert(_verification_bm->isMarked(addr), "tautology"); | |
7736 assert(_cms_bm->isMarked(addr), "tautology"); | |
7737 | |
7738 assert(_mark_stack->isEmpty(), | |
7739 "should drain stack to limit stack usage"); | |
7740 // 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
|
7741 oop obj = oop(addr); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7742 assert(obj->is_oop(), "should be an oop"); |
0 | 7743 assert(_finger <= addr, "_finger runneth ahead"); |
7744 // 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
|
7745 _finger = addr + obj->size(); |
0 | 7746 assert(_finger > addr, "we just incremented it above"); |
7747 // Note: the finger doesn't advance while we drain | |
7748 // the stack below. | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7749 bool res = _mark_stack->push(obj); |
0 | 7750 assert(res, "Empty non-zero size stack should have space for single push"); |
7751 while (!_mark_stack->isEmpty()) { | |
7752 oop new_oop = _mark_stack->pop(); | |
7753 assert(new_oop->is_oop(), "Oops! expected to pop an oop"); | |
7754 // now scan this oop's oops | |
7755 new_oop->oop_iterate(&_pam_verify_closure); | |
7756 } | |
7757 assert(_mark_stack->isEmpty(), "tautology, emphasizing post-condition"); | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7758 return true; |
0 | 7759 } |
7760 | |
7761 PushAndMarkVerifyClosure::PushAndMarkVerifyClosure( | |
7762 CMSCollector* collector, MemRegion span, | |
7763 CMSBitMap* verification_bm, CMSBitMap* cms_bm, | |
7764 CMSMarkStack* mark_stack): | |
20268
4c1b88a53c74
8046670: Make CMS metadata aware closures applicable for other collectors
stefank
parents:
20264
diff
changeset
|
7765 MetadataAwareOopClosure(collector->ref_processor()), |
0 | 7766 _collector(collector), |
7767 _span(span), | |
7768 _verification_bm(verification_bm), | |
7769 _cms_bm(cms_bm), | |
7770 _mark_stack(mark_stack) | |
7771 { } | |
7772 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7773 void PushAndMarkVerifyClosure::do_oop(oop* 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
|
7774 void PushAndMarkVerifyClosure::do_oop(narrowOop* p) { PushAndMarkVerifyClosure::do_oop_work(p); } |
0 | 7775 |
7776 // Upon stack overflow, we discard (part of) the stack, | |
7777 // remembering the least address amongst those discarded | |
7778 // in CMSCollector's _restart_address. | |
7779 void PushAndMarkVerifyClosure::handle_stack_overflow(HeapWord* lost) { | |
7780 // Remember the least grey address discarded | |
7781 HeapWord* ra = (HeapWord*)_mark_stack->least_value(lost); | |
7782 _collector->lower_restart_addr(ra); | |
7783 _mark_stack->reset(); // discard stack contents | |
7784 _mark_stack->expand(); // expand the stack if possible | |
7785 } | |
7786 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7787 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
|
7788 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
|
7789 HeapWord* addr = (HeapWord*)obj; |
0 | 7790 if (_span.contains(addr) && !_verification_bm->isMarked(addr)) { |
7791 // Oop lies in _span and isn't yet grey or black | |
7792 _verification_bm->mark(addr); // now grey | |
7793 if (!_cms_bm->isMarked(addr)) { | |
7794 oop(addr)->print(); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7795 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
|
7796 addr); |
0 | 7797 fatal("... aborting"); |
7798 } | |
7799 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7800 if (!_mark_stack->push(obj)) { // stack overflow |
0 | 7801 if (PrintCMSStatistics != 0) { |
7802 gclog_or_tty->print_cr("CMS marking stack overflow (benign) at " | |
7803 SIZE_FORMAT, _mark_stack->capacity()); | |
7804 } | |
7805 assert(_mark_stack->isFull(), "Else push should have succeeded"); | |
7806 handle_stack_overflow(addr); | |
7807 } | |
7808 // anything including and to the right of _finger | |
7809 // will be scanned as we iterate over the remainder of the | |
7810 // bit map | |
7811 } | |
7812 } | |
7813 | |
7814 PushOrMarkClosure::PushOrMarkClosure(CMSCollector* collector, | |
7815 MemRegion span, | |
7816 CMSBitMap* bitMap, CMSMarkStack* markStack, | |
7817 HeapWord* finger, MarkFromRootsClosure* parent) : | |
20268
4c1b88a53c74
8046670: Make CMS metadata aware closures applicable for other collectors
stefank
parents:
20264
diff
changeset
|
7818 MetadataAwareOopClosure(collector->ref_processor()), |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7819 _collector(collector), |
0 | 7820 _span(span), |
7821 _bitMap(bitMap), | |
7822 _markStack(markStack), | |
7823 _finger(finger), | |
935 | 7824 _parent(parent) |
0 | 7825 { } |
7826 | |
7827 Par_PushOrMarkClosure::Par_PushOrMarkClosure(CMSCollector* collector, | |
7828 MemRegion span, | |
7829 CMSBitMap* bit_map, | |
7830 OopTaskQueue* work_queue, | |
7831 CMSMarkStack* overflow_stack, | |
7832 HeapWord* finger, | |
7833 HeapWord** global_finger_addr, | |
7834 Par_MarkFromRootsClosure* parent) : | |
20268
4c1b88a53c74
8046670: Make CMS metadata aware closures applicable for other collectors
stefank
parents:
20264
diff
changeset
|
7835 MetadataAwareOopClosure(collector->ref_processor()), |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7836 _collector(collector), |
0 | 7837 _whole_span(collector->_span), |
7838 _span(span), | |
7839 _bit_map(bit_map), | |
7840 _work_queue(work_queue), | |
7841 _overflow_stack(overflow_stack), | |
7842 _finger(finger), | |
7843 _global_finger_addr(global_finger_addr), | |
935 | 7844 _parent(parent) |
0 | 7845 { } |
7846 | |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
7847 // Assumes thread-safe access by callers, who are |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
7848 // responsible for mutual exclusion. |
0 | 7849 void CMSCollector::lower_restart_addr(HeapWord* low) { |
7850 assert(_span.contains(low), "Out of bounds addr"); | |
7851 if (_restart_addr == NULL) { | |
7852 _restart_addr = low; | |
7853 } else { | |
7854 _restart_addr = MIN2(_restart_addr, low); | |
7855 } | |
7856 } | |
7857 | |
7858 // Upon stack overflow, we discard (part of) the stack, | |
7859 // remembering the least address amongst those discarded | |
7860 // in CMSCollector's _restart_address. | |
7861 void PushOrMarkClosure::handle_stack_overflow(HeapWord* lost) { | |
7862 // Remember the least grey address discarded | |
7863 HeapWord* ra = (HeapWord*)_markStack->least_value(lost); | |
7864 _collector->lower_restart_addr(ra); | |
7865 _markStack->reset(); // discard stack contents | |
7866 _markStack->expand(); // expand the stack if possible | |
7867 } | |
7868 | |
7869 // Upon stack overflow, we discard (part of) the stack, | |
7870 // remembering the least address amongst those discarded | |
7871 // in CMSCollector's _restart_address. | |
7872 void Par_PushOrMarkClosure::handle_stack_overflow(HeapWord* lost) { | |
7873 // 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
|
7874 // workers from interfering with the work done below. |
0 | 7875 MutexLockerEx ml(_overflow_stack->par_lock(), |
7876 Mutex::_no_safepoint_check_flag); | |
7877 // Remember the least grey address discarded | |
7878 HeapWord* ra = (HeapWord*)_overflow_stack->least_value(lost); | |
7879 _collector->lower_restart_addr(ra); | |
7880 _overflow_stack->reset(); // discard stack contents | |
7881 _overflow_stack->expand(); // expand the stack if possible | |
7882 } | |
7883 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7884 void PushOrMarkClosure::do_oop(oop obj) { |
0 | 7885 // 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
|
7886 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
|
7887 HeapWord* addr = (HeapWord*)obj; |
0 | 7888 if (_span.contains(addr) && !_bitMap->isMarked(addr)) { |
7889 // Oop lies in _span and isn't yet grey or black | |
7890 _bitMap->mark(addr); // now grey | |
7891 if (addr < _finger) { | |
7892 // the bit map iteration has already either passed, or | |
7893 // sampled, this bit in the bit map; we'll need to | |
7894 // use the marking stack to scan this oop's oops. | |
7895 bool simulate_overflow = false; | |
7896 NOT_PRODUCT( | |
7897 if (CMSMarkStackOverflowALot && | |
7898 _collector->simulate_overflow()) { | |
7899 // simulate a stack overflow | |
7900 simulate_overflow = true; | |
7901 } | |
7902 ) | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7903 if (simulate_overflow || !_markStack->push(obj)) { // stack overflow |
0 | 7904 if (PrintCMSStatistics != 0) { |
7905 gclog_or_tty->print_cr("CMS marking stack overflow (benign) at " | |
7906 SIZE_FORMAT, _markStack->capacity()); | |
7907 } | |
7908 assert(simulate_overflow || _markStack->isFull(), "Else push should have succeeded"); | |
7909 handle_stack_overflow(addr); | |
7910 } | |
7911 } | |
7912 // anything including and to the right of _finger | |
7913 // will be scanned as we iterate over the remainder of the | |
7914 // bit map | |
7915 do_yield_check(); | |
7916 } | |
7917 } | |
7918 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7919 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
|
7920 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
|
7921 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7922 void Par_PushOrMarkClosure::do_oop(oop obj) { |
0 | 7923 // 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
|
7924 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
|
7925 HeapWord* addr = (HeapWord*)obj; |
0 | 7926 if (_whole_span.contains(addr) && !_bit_map->isMarked(addr)) { |
7927 // Oop lies in _span and isn't yet grey or black | |
7928 // We read the global_finger (volatile read) strictly after marking oop | |
7929 bool res = _bit_map->par_mark(addr); // now grey | |
7930 volatile HeapWord** gfa = (volatile HeapWord**)_global_finger_addr; | |
7931 // Should we push this marked oop on our stack? | |
7932 // -- if someone else marked it, nothing to do | |
7933 // -- if target oop is above global finger nothing to do | |
7934 // -- if target oop is in chunk and above local finger | |
7935 // then nothing to do | |
7936 // -- else push on work queue | |
7937 if ( !res // someone else marked it, they will deal with it | |
7938 || (addr >= *gfa) // will be scanned in a later task | |
7939 || (_span.contains(addr) && addr >= _finger)) { // later in this chunk | |
7940 return; | |
7941 } | |
7942 // the bit map iteration has already either passed, or | |
7943 // sampled, this bit in the bit map; we'll need to | |
7944 // use the marking stack to scan this oop's oops. | |
7945 bool simulate_overflow = false; | |
7946 NOT_PRODUCT( | |
7947 if (CMSMarkStackOverflowALot && | |
7948 _collector->simulate_overflow()) { | |
7949 // simulate a stack overflow | |
7950 simulate_overflow = true; | |
7951 } | |
7952 ) | |
7953 if (simulate_overflow || | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7954 !(_work_queue->push(obj) || _overflow_stack->par_push(obj))) { |
0 | 7955 // stack overflow |
7956 if (PrintCMSStatistics != 0) { | |
7957 gclog_or_tty->print_cr("CMS marking stack overflow (benign) at " | |
7958 SIZE_FORMAT, _overflow_stack->capacity()); | |
7959 } | |
7960 // We cannot assert that the overflow stack is full because | |
7961 // it may have been emptied since. | |
7962 assert(simulate_overflow || | |
7963 _work_queue->size() == _work_queue->max_elems(), | |
7964 "Else push should have succeeded"); | |
7965 handle_stack_overflow(addr); | |
7966 } | |
7967 do_yield_check(); | |
7968 } | |
7969 } | |
7970 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7971 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
|
7972 void Par_PushOrMarkClosure::do_oop(narrowOop* p) { Par_PushOrMarkClosure::do_oop_work(p); } |
0 | 7973 |
7974 PushAndMarkClosure::PushAndMarkClosure(CMSCollector* collector, | |
7975 MemRegion span, | |
7976 ReferenceProcessor* rp, | |
7977 CMSBitMap* bit_map, | |
7978 CMSBitMap* mod_union_table, | |
7979 CMSMarkStack* mark_stack, | |
7980 bool concurrent_precleaning): | |
20268
4c1b88a53c74
8046670: Make CMS metadata aware closures applicable for other collectors
stefank
parents:
20264
diff
changeset
|
7981 MetadataAwareOopClosure(rp), |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7982 _collector(collector), |
0 | 7983 _span(span), |
7984 _bit_map(bit_map), | |
7985 _mod_union_table(mod_union_table), | |
7986 _mark_stack(mark_stack), | |
935 | 7987 _concurrent_precleaning(concurrent_precleaning) |
0 | 7988 { |
7989 assert(_ref_processor != NULL, "_ref_processor shouldn't be NULL"); | |
7990 } | |
7991 | |
7992 // Grey object rescan during pre-cleaning and second checkpoint phases -- | |
7993 // 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
|
7994 void PushAndMarkClosure::do_oop(oop obj) { |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7995 // Ignore mark word verification. If during concurrent precleaning, |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7996 // the object monitor may be locked. If during the checkpoint |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7997 // 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
|
7998 // 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
|
7999 // the mark word may be NULL). |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
8000 assert(obj->is_oop_or_null(true /* ignore mark word */), |
0 | 8001 "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
|
8002 HeapWord* addr = (HeapWord*)obj; |
0 | 8003 // Check if oop points into the CMS generation |
8004 // and is not marked | |
8005 if (_span.contains(addr) && !_bit_map->isMarked(addr)) { | |
8006 // a white object ... | |
8007 _bit_map->mark(addr); // ... now grey | |
8008 // push on the marking stack (grey set) | |
8009 bool simulate_overflow = false; | |
8010 NOT_PRODUCT( | |
8011 if (CMSMarkStackOverflowALot && | |
8012 _collector->simulate_overflow()) { | |
8013 // simulate a stack overflow | |
8014 simulate_overflow = true; | |
8015 } | |
8016 ) | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8017 if (simulate_overflow || !_mark_stack->push(obj)) { |
0 | 8018 if (_concurrent_precleaning) { |
283
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
8019 // During precleaning we can just dirty the appropriate card(s) |
0 | 8020 // 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
|
8021 // 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
|
8022 // 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
|
8023 // 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
|
8024 // dirty cards. |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
8025 // 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
|
8026 // 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
|
8027 // are required. |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
8028 if (obj->is_objArray()) { |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
8029 size_t sz = obj->size(); |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
8030 HeapWord* end_card_addr = (HeapWord*)round_to( |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
8031 (intptr_t)(addr+sz), CardTableModRefBS::card_size); |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
8032 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
|
8033 assert(!redirty_range.is_empty(), "Arithmetical tautology"); |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
8034 _mod_union_table->mark_range(redirty_range); |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
8035 } else { |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
8036 _mod_union_table->mark(addr); |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
8037 } |
0 | 8038 _collector->_ser_pmc_preclean_ovflw++; |
8039 } else { | |
8040 // During the remark phase, we need to remember this oop | |
8041 // in the overflow list. | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8042 _collector->push_on_overflow_list(obj); |
0 | 8043 _collector->_ser_pmc_remark_ovflw++; |
8044 } | |
8045 } | |
8046 } | |
8047 } | |
8048 | |
8049 Par_PushAndMarkClosure::Par_PushAndMarkClosure(CMSCollector* collector, | |
8050 MemRegion span, | |
8051 ReferenceProcessor* rp, | |
8052 CMSBitMap* bit_map, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
8053 OopTaskQueue* work_queue): |
20268
4c1b88a53c74
8046670: Make CMS metadata aware closures applicable for other collectors
stefank
parents:
20264
diff
changeset
|
8054 MetadataAwareOopClosure(rp), |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
8055 _collector(collector), |
0 | 8056 _span(span), |
8057 _bit_map(bit_map), | |
935 | 8058 _work_queue(work_queue) |
0 | 8059 { |
8060 assert(_ref_processor != NULL, "_ref_processor shouldn't be NULL"); | |
8061 } | |
8062 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8063 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
|
8064 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
|
8065 |
0 | 8066 // Grey object rescan during second checkpoint phase -- |
8067 // the parallel version. | |
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 obj) { |
0 | 8069 // In the assert below, we ignore the mark word because |
8070 // this oop may point to an already visited object that is | |
8071 // on the overflow stack (in which case the mark word has | |
8072 // been hijacked for chaining into the overflow stack -- | |
8073 // if this is the last object in the overflow stack then | |
8074 // its mark word will be NULL). Because this object may | |
8075 // have been subsequently popped off the global overflow | |
8076 // stack, and the mark word possibly restored to the prototypical | |
8077 // value, by the time we get to examined this failing assert in | |
8078 // the debugger, is_oop_or_null(false) may subsequently start | |
8079 // to hold. | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8080 assert(obj->is_oop_or_null(true), |
0 | 8081 "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
|
8082 HeapWord* addr = (HeapWord*)obj; |
0 | 8083 // Check if oop points into the CMS generation |
8084 // and is not marked | |
8085 if (_span.contains(addr) && !_bit_map->isMarked(addr)) { | |
8086 // a white object ... | |
8087 // If we manage to "claim" the object, by being the | |
8088 // first thread to mark it, then we push it on our | |
8089 // marking stack | |
8090 if (_bit_map->par_mark(addr)) { // ... now grey | |
8091 // push on work queue (grey set) | |
8092 bool simulate_overflow = false; | |
8093 NOT_PRODUCT( | |
8094 if (CMSMarkStackOverflowALot && | |
8095 _collector->par_simulate_overflow()) { | |
8096 // simulate a stack overflow | |
8097 simulate_overflow = true; | |
8098 } | |
8099 ) | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8100 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
|
8101 _collector->par_push_on_overflow_list(obj); |
0 | 8102 _collector->_par_pmc_remark_ovflw++; // imprecise OK: no need to CAS |
8103 } | |
8104 } // Else, some other thread got there first | |
8105 } | |
8106 } | |
8107 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8108 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
|
8109 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
|
8110 |
0 | 8111 void CMSPrecleanRefsYieldClosure::do_yield_work() { |
8112 Mutex* bml = _collector->bitMapLock(); | |
8113 assert_lock_strong(bml); | |
8114 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
8115 "CMS thread should hold CMS token"); | |
8116 | |
8117 bml->unlock(); | |
8118 ConcurrentMarkSweepThread::desynchronize(true); | |
8119 | |
8120 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
8121 | |
8122 _collector->stopTimer(); | |
8123 GCPauseTimer p(_collector->size_policy()->concurrent_timer_ptr()); | |
8124 if (PrintCMSStatistics != 0) { | |
8125 _collector->incrementYields(); | |
8126 } | |
8127 _collector->icms_wait(); | |
8128 | |
8129 // See the comment in coordinator_yield() | |
8130 for (unsigned i = 0; i < CMSYieldSleepCount && | |
8131 ConcurrentMarkSweepThread::should_yield() && | |
8132 !CMSCollector::foregroundGCIsActive(); ++i) { | |
8133 os::sleep(Thread::current(), 1, false); | |
8134 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
8135 } | |
8136 | |
8137 ConcurrentMarkSweepThread::synchronize(true); | |
8138 bml->lock(); | |
8139 | |
8140 _collector->startTimer(); | |
8141 } | |
8142 | |
8143 bool CMSPrecleanRefsYieldClosure::should_return() { | |
8144 if (ConcurrentMarkSweepThread::should_yield()) { | |
8145 do_yield_work(); | |
8146 } | |
8147 return _collector->foregroundGCIsActive(); | |
8148 } | |
8149 | |
8150 void MarkFromDirtyCardsClosure::do_MemRegion(MemRegion mr) { | |
8151 assert(((size_t)mr.start())%CardTableModRefBS::card_size_in_words == 0, | |
8152 "mr should be aligned to start at a card boundary"); | |
8153 // We'd like to assert: | |
8154 // assert(mr.word_size()%CardTableModRefBS::card_size_in_words == 0, | |
8155 // "mr should be a range of cards"); | |
8156 // However, that would be too strong in one case -- the last | |
8157 // partition ends at _unallocated_block which, in general, can be | |
8158 // an arbitrary boundary, not necessarily card aligned. | |
8159 if (PrintCMSStatistics != 0) { | |
8160 _num_dirty_cards += | |
8161 mr.word_size()/CardTableModRefBS::card_size_in_words; | |
8162 } | |
8163 _space->object_iterate_mem(mr, &_scan_cl); | |
8164 } | |
8165 | |
8166 SweepClosure::SweepClosure(CMSCollector* collector, | |
8167 ConcurrentMarkSweepGeneration* g, | |
8168 CMSBitMap* bitMap, bool should_yield) : | |
8169 _collector(collector), | |
8170 _g(g), | |
8171 _sp(g->cmsSpace()), | |
8172 _limit(_sp->sweep_limit()), | |
8173 _freelistLock(_sp->freelistLock()), | |
8174 _bitMap(bitMap), | |
8175 _yield(should_yield), | |
8176 _inFreeRange(false), // No free range at beginning of sweep | |
8177 _freeRangeInFreeLists(false), // No free range at beginning of sweep | |
8178 _lastFreeRangeCoalesced(false), | |
8179 _freeFinger(g->used_region().start()) | |
8180 { | |
8181 NOT_PRODUCT( | |
8182 _numObjectsFreed = 0; | |
8183 _numWordsFreed = 0; | |
8184 _numObjectsLive = 0; | |
8185 _numWordsLive = 0; | |
8186 _numObjectsAlreadyFree = 0; | |
8187 _numWordsAlreadyFree = 0; | |
8188 _last_fc = NULL; | |
8189 | |
8190 _sp->initializeIndexedFreeListArrayReturnedBytes(); | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8191 _sp->dictionary()->initialize_dict_returned_bytes(); |
0 | 8192 ) |
8193 assert(_limit >= _sp->bottom() && _limit <= _sp->end(), | |
8194 "sweep _limit out of bounds"); | |
8195 if (CMSTraceSweeper) { | |
3405
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8196 gclog_or_tty->print_cr("\n====================\nStarting new sweep with limit " PTR_FORMAT, |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8197 _limit); |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8198 } |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8199 } |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8200 |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8201 void SweepClosure::print_on(outputStream* st) const { |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8202 tty->print_cr("_sp = [" PTR_FORMAT "," PTR_FORMAT ")", |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8203 _sp->bottom(), _sp->end()); |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8204 tty->print_cr("_limit = " PTR_FORMAT, _limit); |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8205 tty->print_cr("_freeFinger = " PTR_FORMAT, _freeFinger); |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8206 NOT_PRODUCT(tty->print_cr("_last_fc = " PTR_FORMAT, _last_fc);) |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8207 tty->print_cr("_inFreeRange = %d, _freeRangeInFreeLists = %d, _lastFreeRangeCoalesced = %d", |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8208 _inFreeRange, _freeRangeInFreeLists, _lastFreeRangeCoalesced); |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8209 } |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8210 |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8211 #ifndef PRODUCT |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8212 // Assertion checking only: no useful work in product mode -- |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8213 // however, if any of the flags below become product flags, |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8214 // you may need to review this code to see if it needs to be |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8215 // enabled in product mode. |
0 | 8216 SweepClosure::~SweepClosure() { |
8217 assert_lock_strong(_freelistLock); | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8218 assert(_limit >= _sp->bottom() && _limit <= _sp->end(), |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8219 "sweep _limit out of bounds"); |
0 | 8220 if (inFreeRange()) { |
3405
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8221 warning("inFreeRange() should have been reset; dumping state of SweepClosure"); |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8222 print(); |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8223 ShouldNotReachHere(); |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8224 } |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8225 if (Verbose && PrintGC) { |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8226 gclog_or_tty->print("Collected "SIZE_FORMAT" objects, " SIZE_FORMAT " bytes", |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8227 _numObjectsFreed, _numWordsFreed*sizeof(HeapWord)); |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8228 gclog_or_tty->print_cr("\nLive "SIZE_FORMAT" objects, " |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8229 SIZE_FORMAT" bytes " |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8230 "Already free "SIZE_FORMAT" objects, "SIZE_FORMAT" bytes", |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8231 _numObjectsLive, _numWordsLive*sizeof(HeapWord), |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8232 _numObjectsAlreadyFree, _numWordsAlreadyFree*sizeof(HeapWord)); |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8233 size_t totalBytes = (_numWordsFreed + _numWordsLive + _numWordsAlreadyFree) |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8234 * sizeof(HeapWord); |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8235 gclog_or_tty->print_cr("Total sweep: "SIZE_FORMAT" bytes", totalBytes); |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8236 |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8237 if (PrintCMSStatistics && CMSVerifyReturnedBytes) { |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8238 size_t indexListReturnedBytes = _sp->sumIndexedFreeListArrayReturnedBytes(); |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8239 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
|
8240 size_t returned_bytes = indexListReturnedBytes + dict_returned_bytes; |
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8241 gclog_or_tty->print("Returned "SIZE_FORMAT" bytes", returned_bytes); |
3405
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8242 gclog_or_tty->print(" Indexed List Returned "SIZE_FORMAT" bytes", |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8243 indexListReturnedBytes); |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8244 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
|
8245 dict_returned_bytes); |
3405
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8246 } |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8247 } |
0 | 8248 if (CMSTraceSweeper) { |
3405
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8249 gclog_or_tty->print_cr("end of sweep with _limit = " PTR_FORMAT "\n================", |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8250 _limit); |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8251 } |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8252 } |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8253 #endif // PRODUCT |
0 | 8254 |
8255 void SweepClosure::initialize_free_range(HeapWord* freeFinger, | |
8256 bool freeRangeInFreeLists) { | |
8257 if (CMSTraceSweeper) { | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8258 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
|
8259 freeFinger, freeRangeInFreeLists); |
0 | 8260 } |
8261 assert(!inFreeRange(), "Trampling existing free range"); | |
8262 set_inFreeRange(true); | |
8263 set_lastFreeRangeCoalesced(false); | |
8264 | |
8265 set_freeFinger(freeFinger); | |
8266 set_freeRangeInFreeLists(freeRangeInFreeLists); | |
8267 if (CMSTestInFreeList) { | |
8268 if (freeRangeInFreeLists) { | |
8269 FreeChunk* fc = (FreeChunk*) freeFinger; | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8270 assert(fc->is_free(), "A chunk on the free list should be free."); |
0 | 8271 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
|
8272 assert(_sp->verify_chunk_in_free_list(fc), "Chunk is not in free lists"); |
0 | 8273 } |
8274 } | |
8275 } | |
8276 | |
8277 // Note that the sweeper runs concurrently with mutators. Thus, | |
8278 // it is possible for direct allocation in this generation to happen | |
8279 // in the middle of the sweep. Note that the sweeper also coalesces | |
8280 // contiguous free blocks. Thus, unless the sweeper and the allocator | |
8281 // synchronize appropriately freshly allocated blocks may get swept up. | |
8282 // This is accomplished by the sweeper locking the free lists while | |
8283 // it is sweeping. Thus blocks that are determined to be free are | |
8284 // indeed free. There is however one additional complication: | |
8285 // blocks that have been allocated since the final checkpoint and | |
8286 // mark, will not have been marked and so would be treated as | |
8287 // unreachable and swept up. To prevent this, the allocator marks | |
8288 // the bit map when allocating during the sweep phase. This leads, | |
8289 // however, to a further complication -- objects may have been allocated | |
8290 // but not yet initialized -- in the sense that the header isn't yet | |
8291 // installed. The sweeper can not then determine the size of the block | |
8292 // in order to skip over it. To deal with this case, we use a technique | |
8293 // (due to Printezis) to encode such uninitialized block sizes in the | |
8294 // bit map. Since the bit map uses a bit per every HeapWord, but the | |
8295 // CMS generation has a minimum object size of 3 HeapWords, it follows | |
8296 // that "normal marks" won't be adjacent in the bit map (there will | |
8297 // always be at least two 0 bits between successive 1 bits). We make use | |
8298 // of these "unused" bits to represent uninitialized blocks -- the bit | |
8299 // corresponding to the start of the uninitialized object and the next | |
8300 // bit are both set. Finally, a 1 bit marks the end of the object that | |
8301 // started with the two consecutive 1 bits to indicate its potentially | |
8302 // uninitialized state. | |
8303 | |
8304 size_t SweepClosure::do_blk_careful(HeapWord* addr) { | |
8305 FreeChunk* fc = (FreeChunk*)addr; | |
8306 size_t res; | |
8307 | |
1720
5ed703250bff
6977970: CMS: concurrentMarkSweepGeneration.cpp:7947 assert(addr <= _limit) failed: sweep invariant
ysr
parents:
1716
diff
changeset
|
8308 // 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
|
8309 // 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
|
8310 // 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
|
8311 // 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
|
8312 // with a newly expanded chunk (this happens when _limit was set to the |
3405
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8313 // previous _end of the space), so we may have stepped past _limit: |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8314 // 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
|
8315 if (addr >= _limit) { // we have swept up to or past the limit: finish up |
0 | 8316 assert(_limit >= _sp->bottom() && _limit <= _sp->end(), |
8317 "sweep _limit out of bounds"); | |
1720
5ed703250bff
6977970: CMS: concurrentMarkSweepGeneration.cpp:7947 assert(addr <= _limit) failed: sweep invariant
ysr
parents:
1716
diff
changeset
|
8318 assert(addr < _sp->end(), "addr out of bounds"); |
3405
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8319 // 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
|
8320 // coalesced chunk to the appropriate free list. |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8321 if (inFreeRange()) { |
3405
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8322 assert(freeFinger() >= _sp->bottom() && freeFinger() < _limit, |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8323 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
|
8324 flush_cur_free_chunk(freeFinger(), |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8325 pointer_delta(addr, freeFinger())); |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8326 if (CMSTraceSweeper) { |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8327 gclog_or_tty->print("Sweep: last chunk: "); |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8328 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
|
8329 "[coalesced:"SIZE_FORMAT"]\n", |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8330 freeFinger(), pointer_delta(addr, freeFinger()), |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8331 lastFreeRangeCoalesced()); |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8332 } |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8333 } |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8334 |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8335 // help the iterator loop finish |
1720
5ed703250bff
6977970: CMS: concurrentMarkSweepGeneration.cpp:7947 assert(addr <= _limit) failed: sweep invariant
ysr
parents:
1716
diff
changeset
|
8336 return pointer_delta(_sp->end(), addr); |
5ed703250bff
6977970: CMS: concurrentMarkSweepGeneration.cpp:7947 assert(addr <= _limit) failed: sweep invariant
ysr
parents:
1716
diff
changeset
|
8337 } |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8338 |
1720
5ed703250bff
6977970: CMS: concurrentMarkSweepGeneration.cpp:7947 assert(addr <= _limit) failed: sweep invariant
ysr
parents:
1716
diff
changeset
|
8339 assert(addr < _limit, "sweep invariant"); |
0 | 8340 // check if we should yield |
8341 do_yield_check(addr); | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8342 if (fc->is_free()) { |
0 | 8343 // Chunk that is already free |
8344 res = fc->size(); | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8345 do_already_free_chunk(fc); |
0 | 8346 debug_only(_sp->verifyFreeLists()); |
3405
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8347 // If we flush the chunk at hand in lookahead_and_flush() |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8348 // and it's coalesced with a preceding chunk, then the |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8349 // process of "mangling" the payload of the coalesced block |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8350 // will cause erasure of the size information from the |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8351 // (erstwhile) header of all the coalesced blocks but the |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8352 // first, so the first disjunct in the assert will not hold |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8353 // in that specific case (in which case the second disjunct |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8354 // will hold). |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8355 assert(res == fc->size() || ((HeapWord*)fc) + res >= _limit, |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8356 "Otherwise the size info doesn't change at this step"); |
0 | 8357 NOT_PRODUCT( |
8358 _numObjectsAlreadyFree++; | |
8359 _numWordsAlreadyFree += res; | |
8360 ) | |
8361 NOT_PRODUCT(_last_fc = fc;) | |
8362 } else if (!_bitMap->isMarked(addr)) { | |
8363 // Chunk is fresh garbage | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8364 res = do_garbage_chunk(fc); |
0 | 8365 debug_only(_sp->verifyFreeLists()); |
8366 NOT_PRODUCT( | |
8367 _numObjectsFreed++; | |
8368 _numWordsFreed += res; | |
8369 ) | |
8370 } else { | |
8371 // Chunk that is alive. | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8372 res = do_live_chunk(fc); |
0 | 8373 debug_only(_sp->verifyFreeLists()); |
8374 NOT_PRODUCT( | |
8375 _numObjectsLive++; | |
8376 _numWordsLive += res; | |
8377 ) | |
8378 } | |
8379 return res; | |
8380 } | |
8381 | |
8382 // For the smart allocation, record following | |
8383 // split deaths - a free chunk is removed from its free list because | |
8384 // it is being split into two or more chunks. | |
8385 // split birth - a free chunk is being added to its free list because | |
8386 // a larger free chunk has been split and resulted in this free chunk. | |
8387 // coal death - a free chunk is being removed from its free list because | |
8388 // it is being coalesced into a large free chunk. | |
8389 // coal birth - a free chunk is being added to its free list because | |
8390 // it was created when two or more free chunks where coalesced into | |
8391 // this free chunk. | |
8392 // | |
8393 // These statistics are used to determine the desired number of free | |
8394 // chunks of a given size. The desired number is chosen to be relative | |
8395 // to the end of a CMS sweep. The desired number at the end of a sweep | |
8396 // is the | |
8397 // count-at-end-of-previous-sweep (an amount that was enough) | |
8398 // - count-at-beginning-of-current-sweep (the excess) | |
8399 // + split-births (gains in this size during interval) | |
8400 // - split-deaths (demands on this size during interval) | |
8401 // where the interval is from the end of one sweep to the end of the | |
8402 // next. | |
8403 // | |
8404 // When sweeping the sweeper maintains an accumulated chunk which is | |
8405 // the chunk that is made up of chunks that have been coalesced. That | |
8406 // will be termed the left-hand chunk. A new chunk of garbage that | |
8407 // is being considered for coalescing will be referred to as the | |
8408 // right-hand chunk. | |
8409 // | |
8410 // When making a decision on whether to coalesce a right-hand chunk with | |
8411 // the current left-hand chunk, the current count vs. the desired count | |
8412 // of the left-hand chunk is considered. Also if the right-hand chunk | |
8413 // is near the large chunk at the end of the heap (see | |
8414 // ConcurrentMarkSweepGeneration::isNearLargestChunk()), then the | |
8415 // left-hand chunk is coalesced. | |
8416 // | |
8417 // When making a decision about whether to split a chunk, the desired count | |
8418 // vs. the current count of the candidate to be split is also considered. | |
8419 // If the candidate is underpopulated (currently fewer chunks than desired) | |
8420 // a chunk of an overpopulated (currently more chunks than desired) size may | |
8421 // be chosen. The "hint" associated with a free list, if non-null, points | |
8422 // to a free list which may be overpopulated. | |
8423 // | |
8424 | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8425 void SweepClosure::do_already_free_chunk(FreeChunk* fc) { |
3405
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8426 const size_t size = fc->size(); |
0 | 8427 // Chunks that cannot be coalesced are not in the |
8428 // free lists. | |
8429 if (CMSTestInFreeList && !fc->cantCoalesce()) { | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8430 assert(_sp->verify_chunk_in_free_list(fc), |
0 | 8431 "free chunk should be in free lists"); |
8432 } | |
8433 // a chunk that is already free, should not have been | |
8434 // marked in the bit map | |
3405
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8435 HeapWord* const addr = (HeapWord*) fc; |
0 | 8436 assert(!_bitMap->isMarked(addr), "free chunk should be unmarked"); |
8437 // Verify that the bit map has no bits marked between | |
8438 // addr and purported end of this block. | |
8439 _bitMap->verifyNoOneBitsInRange(addr + 1, addr + size); | |
8440 | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8441 // Some chunks cannot be coalesced under any circumstances. |
0 | 8442 // See the definition of cantCoalesce(). |
8443 if (!fc->cantCoalesce()) { | |
8444 // This chunk can potentially be coalesced. | |
8445 if (_sp->adaptive_freelists()) { | |
8446 // All the work is done in | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8447 do_post_free_or_garbage_chunk(fc, size); |
0 | 8448 } else { // Not adaptive free lists |
8449 // this is a free chunk that can potentially be coalesced by the sweeper; | |
8450 if (!inFreeRange()) { | |
8451 // if the next chunk is a free block that can't be coalesced | |
8452 // it doesn't make sense to remove this chunk from the free lists | |
8453 FreeChunk* nextChunk = (FreeChunk*)(addr + size); | |
2136
c91cc404ca46
7011940: iCMS: SIGSEGV in SweepClosure::do_already_free_chunk(FreeChunk*)+0x360
ysr
parents:
2132
diff
changeset
|
8454 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
|
8455 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
|
8456 nextChunk->is_free() && // ... which is free... |
2136
c91cc404ca46
7011940: iCMS: SIGSEGV in SweepClosure::do_already_free_chunk(FreeChunk*)+0x360
ysr
parents:
2132
diff
changeset
|
8457 nextChunk->cantCoalesce()) { // ... but can't be coalesced |
0 | 8458 // nothing to do |
8459 } else { | |
8460 // Potentially the start of a new free range: | |
8461 // Don't eagerly remove it from the free lists. | |
8462 // No need to remove it if it will just be put | |
8463 // back again. (Also from a pragmatic point of view | |
8464 // if it is a free block in a region that is beyond | |
8465 // any allocated blocks, an assertion will fail) | |
8466 // Remember the start of a free run. | |
8467 initialize_free_range(addr, true); | |
8468 // end - can coalesce with next chunk | |
8469 } | |
8470 } else { | |
8471 // the midst of a free range, we are coalescing | |
3405
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8472 print_free_block_coalesced(fc); |
0 | 8473 if (CMSTraceSweeper) { |
8474 gclog_or_tty->print(" -- pick up free block 0x%x (%d)\n", fc, size); | |
8475 } | |
8476 // remove it from the free lists | |
8477 _sp->removeFreeChunkFromFreeLists(fc); | |
8478 set_lastFreeRangeCoalesced(true); | |
8479 // If the chunk is being coalesced and the current free range is | |
8480 // in the free lists, remove the current free range so that it | |
8481 // will be returned to the free lists in its entirety - all | |
8482 // the coalesced pieces included. | |
8483 if (freeRangeInFreeLists()) { | |
8484 FreeChunk* ffc = (FreeChunk*) freeFinger(); | |
8485 assert(ffc->size() == pointer_delta(addr, freeFinger()), | |
8486 "Size of free range is inconsistent with chunk size."); | |
8487 if (CMSTestInFreeList) { | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8488 assert(_sp->verify_chunk_in_free_list(ffc), |
0 | 8489 "free range is not in free lists"); |
8490 } | |
8491 _sp->removeFreeChunkFromFreeLists(ffc); | |
8492 set_freeRangeInFreeLists(false); | |
8493 } | |
8494 } | |
8495 } | |
3405
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8496 // Note that if the chunk is not coalescable (the else arm |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8497 // below), we unconditionally flush, without needing to do |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8498 // a "lookahead," as we do below. |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8499 if (inFreeRange()) lookahead_and_flush(fc, size); |
0 | 8500 } else { |
8501 // Code path common to both original and adaptive free lists. | |
8502 | |
8503 // cant coalesce with previous block; this should be treated | |
8504 // as the end of a free run if any | |
8505 if (inFreeRange()) { | |
8506 // 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
|
8507 assert(freeFinger() < addr, "freeFinger points too high"); |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8508 flush_cur_free_chunk(freeFinger(), pointer_delta(addr, freeFinger())); |
0 | 8509 } |
8510 // else, nothing to do, just continue | |
8511 } | |
8512 } | |
8513 | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8514 size_t SweepClosure::do_garbage_chunk(FreeChunk* fc) { |
0 | 8515 // This is a chunk of garbage. It is not in any free list. |
8516 // Add it to a free list or let it possibly be coalesced into | |
8517 // a larger chunk. | |
3405
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8518 HeapWord* const addr = (HeapWord*) fc; |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8519 const size_t size = CompactibleFreeListSpace::adjustObjectSize(oop(addr)->size()); |
0 | 8520 |
8521 if (_sp->adaptive_freelists()) { | |
8522 // Verify that the bit map has no bits marked between | |
8523 // addr and purported end of just dead object. | |
8524 _bitMap->verifyNoOneBitsInRange(addr + 1, addr + size); | |
8525 | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8526 do_post_free_or_garbage_chunk(fc, size); |
0 | 8527 } else { |
8528 if (!inFreeRange()) { | |
8529 // start of a new free range | |
8530 assert(size > 0, "A free range should have a size"); | |
8531 initialize_free_range(addr, false); | |
8532 } else { | |
8533 // this will be swept up when we hit the end of the | |
8534 // free range | |
8535 if (CMSTraceSweeper) { | |
8536 gclog_or_tty->print(" -- pick up garbage 0x%x (%d) \n", fc, size); | |
8537 } | |
8538 // If the chunk is being coalesced and the current free range is | |
8539 // in the free lists, remove the current free range so that it | |
8540 // will be returned to the free lists in its entirety - all | |
8541 // the coalesced pieces included. | |
8542 if (freeRangeInFreeLists()) { | |
8543 FreeChunk* ffc = (FreeChunk*)freeFinger(); | |
8544 assert(ffc->size() == pointer_delta(addr, freeFinger()), | |
8545 "Size of free range is inconsistent with chunk size."); | |
8546 if (CMSTestInFreeList) { | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8547 assert(_sp->verify_chunk_in_free_list(ffc), |
0 | 8548 "free range is not in free lists"); |
8549 } | |
8550 _sp->removeFreeChunkFromFreeLists(ffc); | |
8551 set_freeRangeInFreeLists(false); | |
8552 } | |
8553 set_lastFreeRangeCoalesced(true); | |
8554 } | |
8555 // this will be swept up when we hit the end of the free range | |
8556 | |
8557 // Verify that the bit map has no bits marked between | |
8558 // addr and purported end of just dead object. | |
8559 _bitMap->verifyNoOneBitsInRange(addr + 1, addr + size); | |
8560 } | |
3405
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8561 assert(_limit >= addr + size, |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8562 "A freshly garbage chunk can't possibly straddle over _limit"); |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8563 if (inFreeRange()) lookahead_and_flush(fc, size); |
0 | 8564 return size; |
8565 } | |
8566 | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8567 size_t SweepClosure::do_live_chunk(FreeChunk* fc) { |
0 | 8568 HeapWord* addr = (HeapWord*) fc; |
8569 // The sweeper has just found a live object. Return any accumulated | |
8570 // left hand chunk to the free lists. | |
8571 if (inFreeRange()) { | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8572 assert(freeFinger() < addr, "freeFinger points too high"); |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8573 flush_cur_free_chunk(freeFinger(), pointer_delta(addr, freeFinger())); |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8574 } |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8575 |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8576 // This object is live: we'd normally expect this to be |
0 | 8577 // an oop, and like to assert the following: |
8578 // assert(oop(addr)->is_oop(), "live block should be an oop"); | |
8579 // However, as we commented above, this may be an object whose | |
8580 // header hasn't yet been initialized. | |
8581 size_t size; | |
8582 assert(_bitMap->isMarked(addr), "Tautology for this control point"); | |
8583 if (_bitMap->isMarked(addr + 1)) { | |
8584 // Determine the size from the bit map, rather than trying to | |
8585 // compute it from the object header. | |
8586 HeapWord* nextOneAddr = _bitMap->getNextMarkedWordAddress(addr + 2); | |
8587 size = pointer_delta(nextOneAddr + 1, addr); | |
8588 assert(size == CompactibleFreeListSpace::adjustObjectSize(size), | |
8589 "alignment problem"); | |
8590 | |
9152 | 8591 #ifdef ASSERT |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
8592 if (oop(addr)->klass_or_null() != NULL) { |
0 | 8593 // Ignore mark word because we are running concurrent with mutators |
8594 assert(oop(addr)->is_oop(true), "live block should be an oop"); | |
8595 assert(size == | |
8596 CompactibleFreeListSpace::adjustObjectSize(oop(addr)->size()), | |
8597 "P-mark and computed size do not agree"); | |
8598 } | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8599 #endif |
0 | 8600 |
8601 } else { | |
8602 // 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
|
8603 assert(oop(addr)->klass_or_null() != NULL, |
0 | 8604 "Should be an initialized object"); |
8605 // Ignore mark word because we are running concurrent with mutators | |
8606 assert(oop(addr)->is_oop(true), "live block should be an oop"); | |
8607 // Verify that the bit map has no bits marked between | |
8608 // addr and purported end of this block. | |
8609 size = CompactibleFreeListSpace::adjustObjectSize(oop(addr)->size()); | |
8610 assert(size >= 3, "Necessary for Printezis marks to work"); | |
8611 assert(!_bitMap->isMarked(addr+1), "Tautology for this control point"); | |
8612 DEBUG_ONLY(_bitMap->verifyNoOneBitsInRange(addr+2, addr+size);) | |
8613 } | |
8614 return size; | |
8615 } | |
8616 | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8617 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
|
8618 size_t chunkSize) { |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8619 // 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
|
8620 // of the adaptive free list allocator. |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8621 const bool fcInFreeLists = fc->is_free(); |
0 | 8622 assert(_sp->adaptive_freelists(), "Should only be used in this case."); |
8623 assert((HeapWord*)fc <= _limit, "sweep invariant"); | |
8624 if (CMSTestInFreeList && fcInFreeLists) { | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8625 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
|
8626 } |
0 | 8627 |
8628 if (CMSTraceSweeper) { | |
8629 gclog_or_tty->print_cr(" -- pick up another chunk at 0x%x (%d)", fc, chunkSize); | |
8630 } | |
8631 | |
3405
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8632 HeapWord* const fc_addr = (HeapWord*) fc; |
0 | 8633 |
8634 bool coalesce; | |
3405
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8635 const size_t left = pointer_delta(fc_addr, freeFinger()); |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8636 const size_t right = chunkSize; |
0 | 8637 switch (FLSCoalescePolicy) { |
8638 // numeric value forms a coalition aggressiveness metric | |
8639 case 0: { // never coalesce | |
8640 coalesce = false; | |
8641 break; | |
8642 } | |
8643 case 1: { // coalesce if left & right chunks on overpopulated lists | |
8644 coalesce = _sp->coalOverPopulated(left) && | |
8645 _sp->coalOverPopulated(right); | |
8646 break; | |
8647 } | |
8648 case 2: { // coalesce if left chunk on overpopulated list (default) | |
8649 coalesce = _sp->coalOverPopulated(left); | |
8650 break; | |
8651 } | |
8652 case 3: { // coalesce if left OR right chunk on overpopulated list | |
8653 coalesce = _sp->coalOverPopulated(left) || | |
8654 _sp->coalOverPopulated(right); | |
8655 break; | |
8656 } | |
8657 case 4: { // always coalesce | |
8658 coalesce = true; | |
8659 break; | |
8660 } | |
8661 default: | |
8662 ShouldNotReachHere(); | |
8663 } | |
8664 | |
8665 // Should the current free range be coalesced? | |
8666 // If the chunk is in a free range and either we decided to coalesce above | |
8667 // or the chunk is near the large block at the end of the heap | |
8668 // (isNearLargestChunk() returns true), then coalesce this chunk. | |
3405
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8669 const bool doCoalesce = inFreeRange() |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8670 && (coalesce || _g->isNearLargestChunk(fc_addr)); |
0 | 8671 if (doCoalesce) { |
8672 // Coalesce the current free range on the left with the new | |
8673 // chunk on the right. If either is on a free list, | |
8674 // it must be removed from the list and stashed in the closure. | |
8675 if (freeRangeInFreeLists()) { | |
3405
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8676 FreeChunk* const ffc = (FreeChunk*)freeFinger(); |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8677 assert(ffc->size() == pointer_delta(fc_addr, freeFinger()), |
0 | 8678 "Size of free range is inconsistent with chunk size."); |
8679 if (CMSTestInFreeList) { | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8680 assert(_sp->verify_chunk_in_free_list(ffc), |
0 | 8681 "Chunk is not in free lists"); |
8682 } | |
8683 _sp->coalDeath(ffc->size()); | |
8684 _sp->removeFreeChunkFromFreeLists(ffc); | |
8685 set_freeRangeInFreeLists(false); | |
8686 } | |
8687 if (fcInFreeLists) { | |
8688 _sp->coalDeath(chunkSize); | |
8689 assert(fc->size() == chunkSize, | |
8690 "The chunk has the wrong size or is not in the free lists"); | |
8691 _sp->removeFreeChunkFromFreeLists(fc); | |
8692 } | |
8693 set_lastFreeRangeCoalesced(true); | |
3405
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8694 print_free_block_coalesced(fc); |
0 | 8695 } else { // not in a free range and/or should not coalesce |
8696 // Return the current free range and start a new one. | |
8697 if (inFreeRange()) { | |
8698 // In a free range but cannot coalesce with the right hand chunk. | |
8699 // 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
|
8700 flush_cur_free_chunk(freeFinger(), |
3405
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8701 pointer_delta(fc_addr, freeFinger())); |
0 | 8702 } |
8703 // Set up for new free range. Pass along whether the right hand | |
8704 // chunk is in the free lists. | |
8705 initialize_free_range((HeapWord*)fc, fcInFreeLists); | |
8706 } | |
8707 } | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8708 |
3405
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8709 // Lookahead flush: |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8710 // If we are tracking a free range, and this is the last chunk that |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8711 // we'll look at because its end crosses past _limit, we'll preemptively |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8712 // flush it along with any free range we may be holding on to. Note that |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8713 // this can be the case only for an already free or freshly garbage |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8714 // chunk. If this block is an object, it can never straddle |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8715 // over _limit. The "straddling" occurs when _limit is set at |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8716 // the previous end of the space when this cycle started, and |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8717 // a subsequent heap expansion caused the previously co-terminal |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8718 // free block to be coalesced with the newly expanded portion, |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8719 // thus rendering _limit a non-block-boundary making it dangerous |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8720 // for the sweeper to step over and examine. |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8721 void SweepClosure::lookahead_and_flush(FreeChunk* fc, size_t chunk_size) { |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8722 assert(inFreeRange(), "Should only be called if currently in a free range."); |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8723 HeapWord* const eob = ((HeapWord*)fc) + chunk_size; |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8724 assert(_sp->used_region().contains(eob - 1), |
12112
1bb10d3170fa
8022817: CMS should not shrink if compaction was not done
jmasa
parents:
12088
diff
changeset
|
8725 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
|
8726 " out of bounds wrt _sp = [" PTR_FORMAT "," PTR_FORMAT ")" |
3405
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8727 " when examining fc = " PTR_FORMAT "(" SIZE_FORMAT ")", |
12112
1bb10d3170fa
8022817: CMS should not shrink if compaction was not done
jmasa
parents:
12088
diff
changeset
|
8728 eob, eob-1, _limit, _sp->bottom(), _sp->end(), fc, chunk_size)); |
3405
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8729 if (eob >= _limit) { |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8730 assert(eob == _limit || fc->is_free(), "Only a free chunk should allow us to cross over the limit"); |
3405
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8731 if (CMSTraceSweeper) { |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8732 gclog_or_tty->print_cr("_limit " PTR_FORMAT " reached or crossed by block " |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8733 "[" PTR_FORMAT "," PTR_FORMAT ") in space " |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8734 "[" PTR_FORMAT "," PTR_FORMAT ")", |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8735 _limit, fc, eob, _sp->bottom(), _sp->end()); |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8736 } |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8737 // Return the storage we are tracking back into the free lists. |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8738 if (CMSTraceSweeper) { |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8739 gclog_or_tty->print_cr("Flushing ... "); |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8740 } |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8741 assert(freeFinger() < eob, "Error"); |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8742 flush_cur_free_chunk( freeFinger(), pointer_delta(eob, freeFinger())); |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8743 } |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8744 } |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8745 |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8746 void SweepClosure::flush_cur_free_chunk(HeapWord* chunk, size_t size) { |
0 | 8747 assert(inFreeRange(), "Should only be called if currently in a free range."); |
8748 assert(size > 0, | |
8749 "A zero sized chunk cannot be added to the free lists."); | |
8750 if (!freeRangeInFreeLists()) { | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8751 if (CMSTestInFreeList) { |
0 | 8752 FreeChunk* fc = (FreeChunk*) chunk; |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8753 fc->set_size(size); |
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8754 assert(!_sp->verify_chunk_in_free_list(fc), |
0 | 8755 "chunk should not be in free lists yet"); |
8756 } | |
8757 if (CMSTraceSweeper) { | |
8758 gclog_or_tty->print_cr(" -- add free block 0x%x (%d) to free lists", | |
8759 chunk, size); | |
8760 } | |
8761 // A new free range is going to be starting. The current | |
8762 // free range has not been added to the free lists yet or | |
8763 // was removed so add it back. | |
8764 // If the current free range was coalesced, then the death | |
8765 // of the free range was recorded. Record a birth now. | |
8766 if (lastFreeRangeCoalesced()) { | |
8767 _sp->coalBirth(size); | |
8768 } | |
8769 _sp->addChunkAndRepairOffsetTable(chunk, size, | |
8770 lastFreeRangeCoalesced()); | |
3405
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8771 } else if (CMSTraceSweeper) { |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8772 gclog_or_tty->print_cr("Already in free list: nothing to flush"); |
0 | 8773 } |
8774 set_inFreeRange(false); | |
8775 set_freeRangeInFreeLists(false); | |
8776 } | |
8777 | |
8778 // We take a break if we've been at this for a while, | |
8779 // so as to avoid monopolizing the locks involved. | |
8780 void SweepClosure::do_yield_work(HeapWord* addr) { | |
8781 // Return current free chunk being used for coalescing (if any) | |
8782 // to the appropriate freelist. After yielding, the next | |
8783 // free block encountered will start a coalescing range of | |
8784 // free blocks. If the next free block is adjacent to the | |
8785 // chunk just flushed, they will need to wait for the next | |
8786 // sweep to be coalesced. | |
8787 if (inFreeRange()) { | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8788 flush_cur_free_chunk(freeFinger(), pointer_delta(addr, freeFinger())); |
0 | 8789 } |
8790 | |
8791 // First give up the locks, then yield, then re-lock. | |
8792 // We should probably use a constructor/destructor idiom to | |
8793 // do this unlock/lock or modify the MutexUnlocker class to | |
8794 // serve our purpose. XXX | |
8795 assert_lock_strong(_bitMap->lock()); | |
8796 assert_lock_strong(_freelistLock); | |
8797 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
8798 "CMS thread should hold CMS token"); | |
8799 _bitMap->lock()->unlock(); | |
8800 _freelistLock->unlock(); | |
8801 ConcurrentMarkSweepThread::desynchronize(true); | |
8802 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
8803 _collector->stopTimer(); | |
8804 GCPauseTimer p(_collector->size_policy()->concurrent_timer_ptr()); | |
8805 if (PrintCMSStatistics != 0) { | |
8806 _collector->incrementYields(); | |
8807 } | |
8808 _collector->icms_wait(); | |
8809 | |
8810 // See the comment in coordinator_yield() | |
8811 for (unsigned i = 0; i < CMSYieldSleepCount && | |
8812 ConcurrentMarkSweepThread::should_yield() && | |
8813 !CMSCollector::foregroundGCIsActive(); ++i) { | |
8814 os::sleep(Thread::current(), 1, false); | |
8815 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
8816 } | |
8817 | |
8818 ConcurrentMarkSweepThread::synchronize(true); | |
8819 _freelistLock->lock(); | |
8820 _bitMap->lock()->lock_without_safepoint_check(); | |
8821 _collector->startTimer(); | |
8822 } | |
8823 | |
8824 #ifndef PRODUCT | |
8825 // This is actually very useful in a product build if it can | |
8826 // be called from the debugger. Compile it into the product | |
8827 // as needed. | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8828 bool debug_verify_chunk_in_free_list(FreeChunk* fc) { |
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8829 return debug_cms_space->verify_chunk_in_free_list(fc); |
0 | 8830 } |
3405
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8831 #endif |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8832 |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8833 void SweepClosure::print_free_block_coalesced(FreeChunk* fc) const { |
0 | 8834 if (CMSTraceSweeper) { |
3405
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8835 gclog_or_tty->print_cr("Sweep:coal_free_blk " PTR_FORMAT " (" SIZE_FORMAT ")", |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8836 fc, fc->size()); |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8837 } |
8cbcd406c42e
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8838 } |
0 | 8839 |
8840 // CMSIsAliveClosure | |
8841 bool CMSIsAliveClosure::do_object_b(oop obj) { | |
8842 HeapWord* addr = (HeapWord*)obj; | |
8843 return addr != NULL && | |
8844 (!_span.contains(addr) || _bit_map->isMarked(addr)); | |
8845 } | |
8846 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
8847 |
935 | 8848 CMSKeepAliveClosure::CMSKeepAliveClosure( CMSCollector* collector, |
8849 MemRegion span, | |
8850 CMSBitMap* bit_map, CMSMarkStack* mark_stack, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
8851 bool cpc): |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
8852 _collector(collector), |
935 | 8853 _span(span), |
8854 _bit_map(bit_map), | |
8855 _mark_stack(mark_stack), | |
8856 _concurrent_precleaning(cpc) { | |
8857 assert(!_span.is_empty(), "Empty span could spell trouble"); | |
8858 } | |
8859 | |
8860 | |
0 | 8861 // CMSKeepAliveClosure: the serial version |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8862 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
|
8863 HeapWord* addr = (HeapWord*)obj; |
0 | 8864 if (_span.contains(addr) && |
8865 !_bit_map->isMarked(addr)) { | |
8866 _bit_map->mark(addr); | |
8867 bool simulate_overflow = false; | |
8868 NOT_PRODUCT( | |
8869 if (CMSMarkStackOverflowALot && | |
8870 _collector->simulate_overflow()) { | |
8871 // simulate a stack overflow | |
8872 simulate_overflow = true; | |
8873 } | |
8874 ) | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8875 if (simulate_overflow || !_mark_stack->push(obj)) { |
452
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8876 if (_concurrent_precleaning) { |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8877 // 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
|
8878 // phase deal with it. |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8879 assert(_collector->overflow_list_is_empty(), "Error"); |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8880 // 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
|
8881 // 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
|
8882 // 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
|
8883 // table. |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8884 if (obj->is_objArray()) { |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8885 size_t sz = obj->size(); |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8886 HeapWord* end_card_addr = |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8887 (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
|
8888 MemRegion redirty_range = MemRegion(addr, end_card_addr); |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8889 assert(!redirty_range.is_empty(), "Arithmetical tautology"); |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8890 _collector->_modUnionTable.mark_range(redirty_range); |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8891 } else { |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8892 _collector->_modUnionTable.mark(addr); |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8893 } |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8894 _collector->_ser_kac_preclean_ovflw++; |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8895 } else { |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8896 _collector->push_on_overflow_list(obj); |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8897 _collector->_ser_kac_ovflw++; |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8898 } |
0 | 8899 } |
8900 } | |
8901 } | |
8902 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8903 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
|
8904 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
|
8905 |
0 | 8906 // CMSParKeepAliveClosure: a parallel version of the above. |
8907 // The work queues are private to each closure (thread), | |
8908 // 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
|
8909 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
|
8910 HeapWord* addr = (HeapWord*)obj; |
0 | 8911 if (_span.contains(addr) && |
8912 !_bit_map->isMarked(addr)) { | |
8913 // In general, during recursive tracing, several threads | |
8914 // may be concurrently getting here; the first one to | |
8915 // "tag" it, claims it. | |
8916 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
|
8917 bool res = _work_queue->push(obj); |
0 | 8918 assert(res, "Low water mark should be much less than capacity"); |
8919 // Do a recursive trim in the hope that this will keep | |
8920 // stack usage lower, but leave some oops for potential stealers | |
8921 trim_queue(_low_water_mark); | |
8922 } // Else, another thread got there first | |
8923 } | |
8924 } | |
8925 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8926 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
|
8927 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
|
8928 |
0 | 8929 void CMSParKeepAliveClosure::trim_queue(uint max) { |
8930 while (_work_queue->size() > max) { | |
8931 oop new_oop; | |
8932 if (_work_queue->pop_local(new_oop)) { | |
8933 assert(new_oop != NULL && new_oop->is_oop(), "Expected an oop"); | |
8934 assert(_bit_map->isMarked((HeapWord*)new_oop), | |
8935 "no white objects on this stack!"); | |
8936 assert(_span.contains((HeapWord*)new_oop), "Out of bounds oop"); | |
8937 // iterate over the oops in this oop, marking and pushing | |
8938 // the ones in CMS heap (i.e. in _span). | |
8939 new_oop->oop_iterate(&_mark_and_push); | |
8940 } | |
8941 } | |
8942 } | |
8943 | |
935 | 8944 CMSInnerParMarkAndPushClosure::CMSInnerParMarkAndPushClosure( |
8945 CMSCollector* collector, | |
8946 MemRegion span, CMSBitMap* bit_map, | |
8947 OopTaskQueue* work_queue): | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
8948 _collector(collector), |
935 | 8949 _span(span), |
8950 _bit_map(bit_map), | |
8951 _work_queue(work_queue) { } | |
8952 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8953 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
|
8954 HeapWord* addr = (HeapWord*)obj; |
0 | 8955 if (_span.contains(addr) && |
8956 !_bit_map->isMarked(addr)) { | |
8957 if (_bit_map->par_mark(addr)) { | |
8958 bool simulate_overflow = false; | |
8959 NOT_PRODUCT( | |
8960 if (CMSMarkStackOverflowALot && | |
8961 _collector->par_simulate_overflow()) { | |
8962 // simulate a stack overflow | |
8963 simulate_overflow = true; | |
8964 } | |
8965 ) | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8966 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
|
8967 _collector->par_push_on_overflow_list(obj); |
0 | 8968 _collector->_par_kac_ovflw++; |
8969 } | |
8970 } // Else another thread got there already | |
8971 } | |
8972 } | |
8973 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8974 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
|
8975 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
|
8976 |
0 | 8977 ////////////////////////////////////////////////////////////////// |
8978 // CMSExpansionCause ///////////////////////////// | |
8979 ////////////////////////////////////////////////////////////////// | |
8980 const char* CMSExpansionCause::to_string(CMSExpansionCause::Cause cause) { | |
8981 switch (cause) { | |
8982 case _no_expansion: | |
8983 return "No expansion"; | |
8984 case _satisfy_free_ratio: | |
8985 return "Free ratio"; | |
8986 case _satisfy_promotion: | |
8987 return "Satisfy promotion"; | |
8988 case _satisfy_allocation: | |
8989 return "allocation"; | |
8990 case _allocate_par_lab: | |
8991 return "Par LAB"; | |
8992 case _allocate_par_spooling_space: | |
8993 return "Par Spooling Space"; | |
8994 case _adaptive_size_policy: | |
8995 return "Ergonomics"; | |
8996 default: | |
8997 return "unknown"; | |
8998 } | |
8999 } | |
9000 | |
9001 void CMSDrainMarkingStackClosure::do_void() { | |
9002 // the max number to take from overflow list at a time | |
9003 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
|
9004 assert(!_concurrent_precleaning || _collector->overflow_list_is_empty(), |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
9005 "Overflow list should be NULL during concurrent phases"); |
0 | 9006 while (!_mark_stack->isEmpty() || |
9007 // if stack is empty, check the overflow list | |
9008 _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
|
9009 oop obj = _mark_stack->pop(); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
9010 HeapWord* addr = (HeapWord*)obj; |
0 | 9011 assert(_span.contains(addr), "Should be within span"); |
9012 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
|
9013 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
|
9014 obj->oop_iterate(_keep_alive); |
0 | 9015 } |
9016 } | |
9017 | |
9018 void CMSParDrainMarkingStackClosure::do_void() { | |
9019 // drain queue | |
9020 trim_queue(0); | |
9021 } | |
9022 | |
9023 // Trim our work_queue so its length is below max at return | |
9024 void CMSParDrainMarkingStackClosure::trim_queue(uint max) { | |
9025 while (_work_queue->size() > max) { | |
9026 oop new_oop; | |
9027 if (_work_queue->pop_local(new_oop)) { | |
9028 assert(new_oop->is_oop(), "Expected an oop"); | |
9029 assert(_bit_map->isMarked((HeapWord*)new_oop), | |
9030 "no white objects on this stack!"); | |
9031 assert(_span.contains((HeapWord*)new_oop), "Out of bounds oop"); | |
9032 // iterate over the oops in this oop, marking and pushing | |
9033 // the ones in CMS heap (i.e. in _span). | |
9034 new_oop->oop_iterate(&_mark_and_push); | |
9035 } | |
9036 } | |
9037 } | |
9038 | |
9039 //////////////////////////////////////////////////////////////////// | |
9040 // Support for Marking Stack Overflow list handling and related code | |
9041 //////////////////////////////////////////////////////////////////// | |
9042 // Much of the following code is similar in shape and spirit to the | |
9043 // code used in ParNewGC. We should try and share that code | |
9044 // as much as possible in the future. | |
9045 | |
9046 #ifndef PRODUCT | |
9047 // Debugging support for CMSStackOverflowALot | |
9048 | |
9049 // It's OK to call this multi-threaded; the worst thing | |
9050 // that can happen is that we'll get a bunch of closely | |
9051 // spaced simulated oveflows, but that's OK, in fact | |
9052 // probably good as it would exercise the overflow code | |
9053 // under contention. | |
9054 bool CMSCollector::simulate_overflow() { | |
9055 if (_overflow_counter-- <= 0) { // just being defensive | |
9056 _overflow_counter = CMSMarkStackOverflowInterval; | |
9057 return true; | |
9058 } else { | |
9059 return false; | |
9060 } | |
9061 } | |
9062 | |
9063 bool CMSCollector::par_simulate_overflow() { | |
9064 return simulate_overflow(); | |
9065 } | |
9066 #endif | |
9067 | |
9068 // Single-threaded | |
9069 bool CMSCollector::take_from_overflow_list(size_t num, CMSMarkStack* stack) { | |
9070 assert(stack->isEmpty(), "Expected precondition"); | |
9071 assert(stack->capacity() > num, "Shouldn't bite more than can chew"); | |
9072 size_t i = num; | |
9073 oop cur = _overflow_list; | |
9074 const markOop proto = markOopDesc::prototype(); | |
534 | 9075 NOT_PRODUCT(ssize_t n = 0;) |
0 | 9076 for (oop next; i > 0 && cur != NULL; cur = next, i--) { |
9077 next = oop(cur->mark()); | |
9078 cur->set_mark(proto); // until proven otherwise | |
9079 assert(cur->is_oop(), "Should be an oop"); | |
9080 bool res = stack->push(cur); | |
9081 assert(res, "Bit off more than can chew?"); | |
9082 NOT_PRODUCT(n++;) | |
9083 } | |
9084 _overflow_list = cur; | |
9085 #ifndef PRODUCT | |
9086 assert(_num_par_pushes >= n, "Too many pops?"); | |
9087 _num_par_pushes -=n; | |
9088 #endif | |
9089 return !stack->isEmpty(); | |
9090 } | |
9091 | |
12316
190899198332
7195622: CheckUnhandledOops has limited usefulness now
hseigel
parents:
12226
diff
changeset
|
9092 #define BUSY (cast_to_oop<intptr_t>(0x1aff1aff)) |
534 | 9093 // (MT-safe) Get a prefix of at most "num" from the list. |
9094 // The overflow list is chained through the mark word of | |
9095 // each object in the list. We fetch the entire list, | |
9096 // break off a prefix of the right size and return the | |
9097 // remainder. If other threads try to take objects from | |
9098 // the overflow list at that time, they will wait for | |
9099 // some time to see if data becomes available. If (and | |
9100 // only if) another thread places one or more object(s) | |
9101 // on the global list before we have returned the suffix | |
9102 // to the global list, we will walk down our local list | |
9103 // to find its end and append the global list to | |
9104 // our suffix before returning it. This suffix walk can | |
9105 // prove to be expensive (quadratic in the amount of traffic) | |
9106 // when there are many objects in the overflow list and | |
9107 // there is much producer-consumer contention on the list. | |
9108 // *NOTE*: The overflow list manipulation code here and | |
9109 // in ParNewGeneration:: are very similar in shape, | |
9110 // except that in the ParNew case we use the old (from/eden) | |
9111 // copy of the object to thread the list via its klass word. | |
9112 // Because of the common code, if you make any changes in | |
9113 // the code below, please check the ParNew version to see if | |
9114 // similar changes might be needed. | |
9115 // CR 6797058 has been filed to consolidate the common code. | |
0 | 9116 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
|
9117 OopTaskQueue* work_q, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
9118 int no_of_gc_threads) { |
534 | 9119 assert(work_q->size() == 0, "First empty local work queue"); |
0 | 9120 assert(num < work_q->max_elems(), "Can't bite more than we can chew"); |
9121 if (_overflow_list == NULL) { | |
9122 return false; | |
9123 } | |
9124 // Grab the entire list; we'll put back a suffix | |
12316
190899198332
7195622: CheckUnhandledOops has limited usefulness now
hseigel
parents:
12226
diff
changeset
|
9125 oop prefix = cast_to_oop(Atomic::xchg_ptr(BUSY, &_overflow_list)); |
534 | 9126 Thread* tid = Thread::current(); |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
9127 // Before "no_of_gc_threads" was introduced CMSOverflowSpinCount was |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
9128 // set to ParallelGCThreads. |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
9129 size_t CMSOverflowSpinCount = (size_t) no_of_gc_threads; // was ParallelGCThreads; |
534 | 9130 size_t sleep_time_millis = MAX2((size_t)1, num/100); |
9131 // If the list is busy, we spin for a short while, | |
9132 // sleeping between attempts to get the list. | |
9133 for (size_t spin = 0; prefix == BUSY && spin < CMSOverflowSpinCount; spin++) { | |
9134 os::sleep(tid, sleep_time_millis, false); | |
9135 if (_overflow_list == NULL) { | |
9136 // Nothing left to take | |
9137 return false; | |
9138 } else if (_overflow_list != BUSY) { | |
9139 // Try and grab the prefix | |
12316
190899198332
7195622: CheckUnhandledOops has limited usefulness now
hseigel
parents:
12226
diff
changeset
|
9140 prefix = cast_to_oop(Atomic::xchg_ptr(BUSY, &_overflow_list)); |
534 | 9141 } |
9142 } | |
9143 // If the list was found to be empty, or we spun long | |
9144 // enough, we give up and return empty-handed. If we leave | |
9145 // the list in the BUSY state below, it must be the case that | |
9146 // some other thread holds the overflow list and will set it | |
9147 // to a non-BUSY state in the future. | |
9148 if (prefix == NULL || prefix == BUSY) { | |
9149 // Nothing to take or waited long enough | |
9150 if (prefix == NULL) { | |
9151 // Write back the NULL in case we overwrote it with BUSY above | |
9152 // and it is still the same value. | |
9153 (void) Atomic::cmpxchg_ptr(NULL, &_overflow_list, BUSY); | |
9154 } | |
9155 return false; | |
9156 } | |
9157 assert(prefix != NULL && prefix != BUSY, "Error"); | |
0 | 9158 size_t i = num; |
9159 oop cur = prefix; | |
534 | 9160 // Walk down the first "num" objects, unless we reach the end. |
0 | 9161 for (; i > 1 && cur->mark() != NULL; cur = oop(cur->mark()), i--); |
534 | 9162 if (cur->mark() == NULL) { |
9163 // We have "num" or fewer elements in the list, so there | |
9164 // is nothing to return to the global list. | |
9165 // Write back the NULL in lieu of the BUSY we wrote | |
9166 // above, if it is still the same value. | |
9167 if (_overflow_list == BUSY) { | |
9168 (void) Atomic::cmpxchg_ptr(NULL, &_overflow_list, BUSY); | |
9169 } | |
9170 } else { | |
9171 // Chop off the suffix and rerturn it to the global list. | |
9172 assert(cur->mark() != BUSY, "Error"); | |
0 | 9173 oop suffix_head = cur->mark(); // suffix will be put back on global list |
9174 cur->set_mark(NULL); // break off suffix | |
534 | 9175 // It's possible that the list is still in the empty(busy) state |
9176 // we left it in a short while ago; in that case we may be | |
9177 // able to place back the suffix without incurring the cost | |
9178 // of a walk down the list. | |
0 | 9179 oop observed_overflow_list = _overflow_list; |
534 | 9180 oop cur_overflow_list = observed_overflow_list; |
9181 bool attached = false; | |
9182 while (observed_overflow_list == BUSY || observed_overflow_list == NULL) { | |
0 | 9183 observed_overflow_list = |
534 | 9184 (oop) Atomic::cmpxchg_ptr(suffix_head, &_overflow_list, cur_overflow_list); |
9185 if (cur_overflow_list == observed_overflow_list) { | |
9186 attached = true; | |
9187 break; | |
9188 } else cur_overflow_list = observed_overflow_list; | |
9189 } | |
9190 if (!attached) { | |
9191 // Too bad, someone else sneaked in (at least) an element; we'll need | |
9192 // to do a splice. Find tail of suffix so we can prepend suffix to global | |
9193 // list. | |
9194 for (cur = suffix_head; cur->mark() != NULL; cur = (oop)(cur->mark())); | |
9195 oop suffix_tail = cur; | |
9196 assert(suffix_tail != NULL && suffix_tail->mark() == NULL, | |
9197 "Tautology"); | |
9198 observed_overflow_list = _overflow_list; | |
9199 do { | |
9200 cur_overflow_list = observed_overflow_list; | |
9201 if (cur_overflow_list != BUSY) { | |
9202 // Do the splice ... | |
9203 suffix_tail->set_mark(markOop(cur_overflow_list)); | |
9204 } else { // cur_overflow_list == BUSY | |
9205 suffix_tail->set_mark(NULL); | |
9206 } | |
9207 // ... and try to place spliced list back on overflow_list ... | |
9208 observed_overflow_list = | |
9209 (oop) Atomic::cmpxchg_ptr(suffix_head, &_overflow_list, cur_overflow_list); | |
9210 } while (cur_overflow_list != observed_overflow_list); | |
9211 // ... until we have succeeded in doing so. | |
9212 } | |
0 | 9213 } |
9214 | |
9215 // Push the prefix elements on work_q | |
9216 assert(prefix != NULL, "control point invariant"); | |
9217 const markOop proto = markOopDesc::prototype(); | |
9218 oop next; | |
534 | 9219 NOT_PRODUCT(ssize_t n = 0;) |
0 | 9220 for (cur = prefix; cur != NULL; cur = next) { |
9221 next = oop(cur->mark()); | |
9222 cur->set_mark(proto); // until proven otherwise | |
9223 assert(cur->is_oop(), "Should be an oop"); | |
9224 bool res = work_q->push(cur); | |
9225 assert(res, "Bit off more than we can chew?"); | |
9226 NOT_PRODUCT(n++;) | |
9227 } | |
9228 #ifndef PRODUCT | |
9229 assert(_num_par_pushes >= n, "Too many pops?"); | |
9230 Atomic::add_ptr(-(intptr_t)n, &_num_par_pushes); | |
9231 #endif | |
9232 return true; | |
9233 } | |
9234 | |
9235 // Single-threaded | |
9236 void CMSCollector::push_on_overflow_list(oop p) { | |
9237 NOT_PRODUCT(_num_par_pushes++;) | |
9238 assert(p->is_oop(), "Not an oop"); | |
9239 preserve_mark_if_necessary(p); | |
9240 p->set_mark((markOop)_overflow_list); | |
9241 _overflow_list = p; | |
9242 } | |
9243 | |
9244 // Multi-threaded; use CAS to prepend to overflow list | |
9245 void CMSCollector::par_push_on_overflow_list(oop p) { | |
9246 NOT_PRODUCT(Atomic::inc_ptr(&_num_par_pushes);) | |
9247 assert(p->is_oop(), "Not an oop"); | |
9248 par_preserve_mark_if_necessary(p); | |
9249 oop observed_overflow_list = _overflow_list; | |
9250 oop cur_overflow_list; | |
9251 do { | |
9252 cur_overflow_list = observed_overflow_list; | |
534 | 9253 if (cur_overflow_list != BUSY) { |
9254 p->set_mark(markOop(cur_overflow_list)); | |
9255 } else { | |
9256 p->set_mark(NULL); | |
9257 } | |
0 | 9258 observed_overflow_list = |
9259 (oop) Atomic::cmpxchg_ptr(p, &_overflow_list, cur_overflow_list); | |
9260 } while (cur_overflow_list != observed_overflow_list); | |
9261 } | |
534 | 9262 #undef BUSY |
0 | 9263 |
9264 // Single threaded | |
9265 // General Note on GrowableArray: pushes may silently fail | |
9266 // because we are (temporarily) out of C-heap for expanding | |
9267 // the stack. The problem is quite ubiquitous and affects | |
9268 // a lot of code in the JVM. The prudent thing for GrowableArray | |
9269 // to do (for now) is to exit with an error. However, that may | |
9270 // be too draconian in some cases because the caller may be | |
534 | 9271 // able to recover without much harm. For such cases, we |
0 | 9272 // should probably introduce a "soft_push" method which returns |
9273 // an indication of success or failure with the assumption that | |
9274 // the caller may be able to recover from a failure; code in | |
9275 // the VM can then be changed, incrementally, to deal with such | |
9276 // failures where possible, thus, incrementally hardening the VM | |
9277 // in such low resource situations. | |
9278 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
|
9279 _preserved_oop_stack.push(p); |
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9280 _preserved_mark_stack.push(m); |
0 | 9281 assert(m == p->mark(), "Mark word changed"); |
1836
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9282 assert(_preserved_oop_stack.size() == _preserved_mark_stack.size(), |
0 | 9283 "bijection"); |
9284 } | |
9285 | |
9286 // Single threaded | |
9287 void CMSCollector::preserve_mark_if_necessary(oop p) { | |
9288 markOop m = p->mark(); | |
9289 if (m->must_be_preserved(p)) { | |
9290 preserve_mark_work(p, m); | |
9291 } | |
9292 } | |
9293 | |
9294 void CMSCollector::par_preserve_mark_if_necessary(oop p) { | |
9295 markOop m = p->mark(); | |
9296 if (m->must_be_preserved(p)) { | |
9297 MutexLockerEx x(ParGCRareEvent_lock, Mutex::_no_safepoint_check_flag); | |
9298 // Even though we read the mark word without holding | |
9299 // the lock, we are assured that it will not change | |
9300 // because we "own" this oop, so no other thread can | |
9301 // be trying to push it on the overflow list; see | |
9302 // the assertion in preserve_mark_work() that checks | |
9303 // that m == p->mark(). | |
9304 preserve_mark_work(p, m); | |
9305 } | |
9306 } | |
9307 | |
9308 // We should be able to do this multi-threaded, | |
9309 // a chunk of stack being a task (this is | |
9310 // correct because each oop only ever appears | |
9311 // once in the overflow list. However, it's | |
9312 // not very easy to completely overlap this with | |
9313 // other operations, so will generally not be done | |
9314 // until all work's been completed. Because we | |
9315 // expect the preserved oop stack (set) to be small, | |
9316 // it's probably fine to do this single-threaded. | |
9317 // We can explore cleverer concurrent/overlapped/parallel | |
9318 // processing of preserved marks if we feel the | |
9319 // need for this in the future. Stack overflow should | |
9320 // be so rare in practice and, when it happens, its | |
9321 // effect on performance so great that this will | |
9322 // likely just be in the noise anyway. | |
9323 void CMSCollector::restore_preserved_marks_if_any() { | |
9324 assert(SafepointSynchronize::is_at_safepoint(), | |
9325 "world should be stopped"); | |
9326 assert(Thread::current()->is_ConcurrentGC_thread() || | |
9327 Thread::current()->is_VM_thread(), | |
9328 "should be single-threaded"); | |
1836
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9329 assert(_preserved_oop_stack.size() == _preserved_mark_stack.size(), |
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9330 "bijection"); |
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9331 |
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9332 while (!_preserved_oop_stack.is_empty()) { |
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9333 oop p = _preserved_oop_stack.pop(); |
0 | 9334 assert(p->is_oop(), "Should be an oop"); |
9335 assert(_span.contains(p), "oop should be in _span"); | |
9336 assert(p->mark() == markOopDesc::prototype(), | |
9337 "Set when taken from overflow list"); | |
1836
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9338 markOop m = _preserved_mark_stack.pop(); |
0 | 9339 p->set_mark(m); |
9340 } | |
1836
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9341 assert(_preserved_mark_stack.is_empty() && _preserved_oop_stack.is_empty(), |
0 | 9342 "stacks were cleared above"); |
9343 } | |
9344 | |
9345 #ifndef PRODUCT | |
9346 bool CMSCollector::no_preserved_marks() const { | |
1836
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9347 return _preserved_mark_stack.is_empty() && _preserved_oop_stack.is_empty(); |
0 | 9348 } |
9349 #endif | |
9350 | |
9351 CMSAdaptiveSizePolicy* ASConcurrentMarkSweepGeneration::cms_size_policy() const | |
9352 { | |
9353 GenCollectedHeap* gch = (GenCollectedHeap*) GenCollectedHeap::heap(); | |
9354 CMSAdaptiveSizePolicy* size_policy = | |
9355 (CMSAdaptiveSizePolicy*) gch->gen_policy()->size_policy(); | |
9356 assert(size_policy->is_gc_cms_adaptive_size_policy(), | |
9357 "Wrong type for size policy"); | |
9358 return size_policy; | |
9359 } | |
9360 | |
9361 void ASConcurrentMarkSweepGeneration::resize(size_t cur_promo_size, | |
9362 size_t desired_promo_size) { | |
9363 if (cur_promo_size < desired_promo_size) { | |
9364 size_t expand_bytes = desired_promo_size - cur_promo_size; | |
9365 if (PrintAdaptiveSizePolicy && Verbose) { | |
9366 gclog_or_tty->print_cr(" ASConcurrentMarkSweepGeneration::resize " | |
9367 "Expanding tenured generation by " SIZE_FORMAT " (bytes)", | |
9368 expand_bytes); | |
9369 } | |
9370 expand(expand_bytes, | |
9371 MinHeapDeltaBytes, | |
9372 CMSExpansionCause::_adaptive_size_policy); | |
9373 } else if (desired_promo_size < cur_promo_size) { | |
9374 size_t shrink_bytes = cur_promo_size - desired_promo_size; | |
9375 if (PrintAdaptiveSizePolicy && Verbose) { | |
9376 gclog_or_tty->print_cr(" ASConcurrentMarkSweepGeneration::resize " | |
9377 "Shrinking tenured generation by " SIZE_FORMAT " (bytes)", | |
9378 shrink_bytes); | |
9379 } | |
9380 shrink(shrink_bytes); | |
9381 } | |
9382 } | |
9383 | |
9384 CMSGCAdaptivePolicyCounters* ASConcurrentMarkSweepGeneration::gc_adaptive_policy_counters() { | |
9385 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
9386 CMSGCAdaptivePolicyCounters* counters = | |
9387 (CMSGCAdaptivePolicyCounters*) gch->collector_policy()->counters(); | |
9388 assert(counters->kind() == GCPolicyCounters::CMSGCAdaptivePolicyCountersKind, | |
9389 "Wrong kind of counters"); | |
9390 return counters; | |
9391 } | |
9392 | |
9393 | |
9394 void ASConcurrentMarkSweepGeneration::update_counters() { | |
9395 if (UsePerfData) { | |
9396 _space_counters->update_all(); | |
9397 _gen_counters->update_all(); | |
9398 CMSGCAdaptivePolicyCounters* counters = gc_adaptive_policy_counters(); | |
9399 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
9400 CMSGCStats* gc_stats_l = (CMSGCStats*) gc_stats(); | |
9401 assert(gc_stats_l->kind() == GCStats::CMSGCStatsKind, | |
9402 "Wrong gc statistics type"); | |
9403 counters->update_counters(gc_stats_l); | |
9404 } | |
9405 } | |
9406 | |
9407 void ASConcurrentMarkSweepGeneration::update_counters(size_t used) { | |
9408 if (UsePerfData) { | |
9409 _space_counters->update_used(used); | |
9410 _space_counters->update_capacity(); | |
9411 _gen_counters->update_all(); | |
9412 | |
9413 CMSGCAdaptivePolicyCounters* counters = gc_adaptive_policy_counters(); | |
9414 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
9415 CMSGCStats* gc_stats_l = (CMSGCStats*) gc_stats(); | |
9416 assert(gc_stats_l->kind() == GCStats::CMSGCStatsKind, | |
9417 "Wrong gc statistics type"); | |
9418 counters->update_counters(gc_stats_l); | |
9419 } | |
9420 } | |
9421 | |
9422 void ASConcurrentMarkSweepGeneration::shrink_by(size_t desired_bytes) { | |
9423 assert_locked_or_safepoint(Heap_lock); | |
9424 assert_lock_strong(freelistLock()); | |
9425 HeapWord* old_end = _cmsSpace->end(); | |
9426 HeapWord* unallocated_start = _cmsSpace->unallocated_block(); | |
9427 assert(old_end >= unallocated_start, "Miscalculation of unallocated_start"); | |
9428 FreeChunk* chunk_at_end = find_chunk_at_end(); | |
9429 if (chunk_at_end == NULL) { | |
9430 // No room to shrink | |
9431 if (PrintGCDetails && Verbose) { | |
9432 gclog_or_tty->print_cr("No room to shrink: old_end " | |
9433 PTR_FORMAT " unallocated_start " PTR_FORMAT | |
9434 " chunk_at_end " PTR_FORMAT, | |
9435 old_end, unallocated_start, chunk_at_end); | |
9436 } | |
9437 return; | |
9438 } else { | |
9439 | |
9440 // Find the chunk at the end of the space and determine | |
9441 // how much it can be shrunk. | |
9442 size_t shrinkable_size_in_bytes = chunk_at_end->size(); | |
9443 size_t aligned_shrinkable_size_in_bytes = | |
9444 align_size_down(shrinkable_size_in_bytes, os::vm_page_size()); | |
6885 | 9445 assert(unallocated_start <= (HeapWord*) chunk_at_end->end(), |
0 | 9446 "Inconsistent chunk at end of space"); |
9447 size_t bytes = MIN2(desired_bytes, aligned_shrinkable_size_in_bytes); | |
9448 size_t word_size_before = heap_word_size(_virtual_space.committed_size()); | |
9449 | |
9450 // Shrink the underlying space | |
9451 _virtual_space.shrink_by(bytes); | |
9452 if (PrintGCDetails && Verbose) { | |
9453 gclog_or_tty->print_cr("ConcurrentMarkSweepGeneration::shrink_by:" | |
9454 " desired_bytes " SIZE_FORMAT | |
9455 " shrinkable_size_in_bytes " SIZE_FORMAT | |
9456 " aligned_shrinkable_size_in_bytes " SIZE_FORMAT | |
9457 " bytes " SIZE_FORMAT, | |
9458 desired_bytes, shrinkable_size_in_bytes, | |
9459 aligned_shrinkable_size_in_bytes, bytes); | |
9460 gclog_or_tty->print_cr(" old_end " SIZE_FORMAT | |
9461 " unallocated_start " SIZE_FORMAT, | |
9462 old_end, unallocated_start); | |
9463 } | |
9464 | |
9465 // If the space did shrink (shrinking is not guaranteed), | |
9466 // shrink the chunk at the end by the appropriate amount. | |
9467 if (((HeapWord*)_virtual_space.high()) < old_end) { | |
9468 size_t new_word_size = | |
9469 heap_word_size(_virtual_space.committed_size()); | |
9470 | |
9471 // Have to remove the chunk from the dictionary because it is changing | |
9472 // size and might be someplace elsewhere in the dictionary. | |
9473 | |
9474 // Get the chunk at end, shrink it, and put it | |
9475 // back. | |
9476 _cmsSpace->removeChunkFromDictionary(chunk_at_end); | |
9477 size_t word_size_change = word_size_before - new_word_size; | |
9478 size_t chunk_at_end_old_size = chunk_at_end->size(); | |
9479 assert(chunk_at_end_old_size >= word_size_change, | |
9480 "Shrink is too large"); | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
9481 chunk_at_end->set_size(chunk_at_end_old_size - |
0 | 9482 word_size_change); |
9483 _cmsSpace->freed((HeapWord*) chunk_at_end->end(), | |
9484 word_size_change); | |
9485 | |
9486 _cmsSpace->returnChunkToDictionary(chunk_at_end); | |
9487 | |
9488 MemRegion mr(_cmsSpace->bottom(), new_word_size); | |
9489 _bts->resize(new_word_size); // resize the block offset shared array | |
9490 Universe::heap()->barrier_set()->resize_covered_region(mr); | |
9491 _cmsSpace->assert_locked(); | |
9492 _cmsSpace->set_end((HeapWord*)_virtual_space.high()); | |
9493 | |
9494 NOT_PRODUCT(_cmsSpace->dictionary()->verify()); | |
9495 | |
9496 // update the space and generation capacity counters | |
9497 if (UsePerfData) { | |
9498 _space_counters->update_capacity(); | |
9499 _gen_counters->update_all(); | |
9500 } | |
9501 | |
9502 if (Verbose && PrintGCDetails) { | |
9503 size_t new_mem_size = _virtual_space.committed_size(); | |
9504 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
|
9505 gclog_or_tty->print_cr("Shrinking %s from " SIZE_FORMAT "K by " SIZE_FORMAT "K to " SIZE_FORMAT "K", |
0 | 9506 name(), old_mem_size/K, bytes/K, new_mem_size/K); |
9507 } | |
9508 } | |
9509 | |
9510 assert(_cmsSpace->unallocated_block() <= _cmsSpace->end(), | |
9511 "Inconsistency at end of space"); | |
6885 | 9512 assert(chunk_at_end->end() == (uintptr_t*) _cmsSpace->end(), |
0 | 9513 "Shrinking is inconsistent"); |
9514 return; | |
9515 } | |
9516 } | |
9517 // Transfer some number of overflown objects to usual marking | |
9518 // stack. Return true if some objects were transferred. | |
9519 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
|
9520 size_t num = MIN2((size_t)(_mark_stack->capacity() - _mark_stack->length())/4, |
0 | 9521 (size_t)ParGCDesiredObjsFromOverflowList); |
9522 | |
9523 bool res = _collector->take_from_overflow_list(num, _mark_stack); | |
9524 assert(_collector->overflow_list_is_empty() || res, | |
9525 "If list is not empty, we should have taken something"); | |
9526 assert(!res || !_mark_stack->isEmpty(), | |
9527 "If we took something, it should now be on our stack"); | |
9528 return res; | |
9529 } | |
9530 | |
9531 size_t MarkDeadObjectsClosure::do_blk(HeapWord* addr) { | |
9532 size_t res = _sp->block_size_no_stall(addr, _collector); | |
9533 if (_sp->block_is_obj(addr)) { | |
9534 if (_live_bit_map->isMarked(addr)) { | |
9535 // It can't have been dead in a previous cycle | |
9536 guarantee(!_dead_bit_map->isMarked(addr), "No resurrection!"); | |
9537 } else { | |
9538 _dead_bit_map->mark(addr); // mark the dead object | |
9539 } | |
9540 } | |
2226
c5a923563727
6912621: iCMS: Error: assert(_markBitMap.isMarked(addr + 1),"Missing Printezis bit?")
ysr
parents:
2177
diff
changeset
|
9541 // Could be 0, if the block size could not be computed without stalling. |
0 | 9542 return res; |
9543 } | |
1703
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9544 |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
3293
diff
changeset
|
9545 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
|
9546 |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9547 switch (phase) { |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9548 case CMSCollector::InitialMarking: |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9549 initialize(true /* fullGC */ , |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
3293
diff
changeset
|
9550 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
|
9551 true /* recordGCBeginTime */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9552 true /* recordPreGCUsage */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9553 false /* recordPeakUsage */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9554 false /* recordPostGCusage */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9555 true /* recordAccumulatedGCTime */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9556 false /* recordGCEndTime */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9557 false /* countCollection */ ); |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9558 break; |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9559 |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9560 case CMSCollector::FinalMarking: |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9561 initialize(true /* fullGC */ , |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
3293
diff
changeset
|
9562 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
|
9563 false /* recordGCBeginTime */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9564 false /* recordPreGCUsage */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9565 false /* recordPeakUsage */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9566 false /* recordPostGCusage */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9567 true /* recordAccumulatedGCTime */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9568 false /* recordGCEndTime */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9569 false /* countCollection */ ); |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9570 break; |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9571 |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9572 case CMSCollector::Sweeping: |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9573 initialize(true /* fullGC */ , |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
3293
diff
changeset
|
9574 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
|
9575 false /* recordGCBeginTime */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9576 false /* recordPreGCUsage */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9577 true /* recordPeakUsage */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9578 true /* recordPostGCusage */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9579 false /* recordAccumulatedGCTime */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9580 true /* recordGCEndTime */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9581 true /* countCollection */ ); |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9582 break; |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9583 |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9584 default: |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9585 ShouldNotReachHere(); |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9586 } |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9587 } |