Mercurial > hg > graal-compiler
annotate src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.hpp @ 9072:8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
Reviewed-by: johnc, ysr
author | jmasa |
---|---|
date | Mon, 11 Feb 2013 10:31:56 -0800 |
parents | f64ffbf81af5 |
children | 7b835924c31c |
rev | line source |
---|---|
0 | 1 /* |
8035 | 2 * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1387
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1387
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:
1387
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_CONCURRENTMARKSWEEPGENERATION_HPP |
26 #define SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_CONCURRENTMARKSWEEPGENERATION_HPP | |
27 | |
28 #include "gc_implementation/shared/gSpaceCounters.hpp" | |
29 #include "gc_implementation/shared/gcStats.hpp" | |
30 #include "gc_implementation/shared/generationCounters.hpp" | |
6026 | 31 #include "memory/freeBlockDictionary.hpp" |
1972 | 32 #include "memory/generation.hpp" |
33 #include "runtime/mutexLocker.hpp" | |
34 #include "runtime/virtualspace.hpp" | |
35 #include "services/memoryService.hpp" | |
36 #include "utilities/bitMap.inline.hpp" | |
37 #include "utilities/stack.inline.hpp" | |
38 #include "utilities/taskqueue.hpp" | |
39 #include "utilities/yieldingWorkgroup.hpp" | |
40 | |
0 | 41 // ConcurrentMarkSweepGeneration is in support of a concurrent |
42 // mark-sweep old generation in the Detlefs-Printezis--Boehm-Demers-Schenker | |
43 // style. We assume, for now, that this generation is always the | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
44 // seniormost generation and for simplicity |
0 | 45 // in the first implementation, that this generation is a single compactible |
46 // space. Neither of these restrictions appears essential, and will be | |
47 // relaxed in the future when more time is available to implement the | |
48 // greater generality (and there's a need for it). | |
49 // | |
50 // Concurrent mode failures are currently handled by | |
51 // means of a sliding mark-compact. | |
52 | |
53 class CMSAdaptiveSizePolicy; | |
54 class CMSConcMarkingTask; | |
55 class CMSGCAdaptivePolicyCounters; | |
56 class ConcurrentMarkSweepGeneration; | |
57 class ConcurrentMarkSweepPolicy; | |
58 class ConcurrentMarkSweepThread; | |
59 class CompactibleFreeListSpace; | |
60 class FreeChunk; | |
61 class PromotionInfo; | |
62 class ScanMarkedObjectsAgainCarefullyClosure; | |
9072
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8035
diff
changeset
|
63 class TenuredGeneration; |
0 | 64 |
65 // A generic CMS bit map. It's the basis for both the CMS marking bit map | |
66 // as well as for the mod union table (in each case only a subset of the | |
67 // methods are used). This is essentially a wrapper around the BitMap class, | |
68 // with one bit per (1<<_shifter) HeapWords. (i.e. for the marking bit map, | |
69 // we have _shifter == 0. and for the mod union table we have | |
70 // shifter == CardTableModRefBS::card_shift - LogHeapWordSize.) | |
71 // XXX 64-bit issues in BitMap? | |
72 class CMSBitMap VALUE_OBJ_CLASS_SPEC { | |
73 friend class VMStructs; | |
74 | |
75 HeapWord* _bmStartWord; // base address of range covered by map | |
76 size_t _bmWordSize; // map size (in #HeapWords covered) | |
77 const int _shifter; // shifts to convert HeapWord to bit position | |
78 VirtualSpace _virtual_space; // underlying the bit map | |
79 BitMap _bm; // the bit map itself | |
80 public: | |
81 Mutex* const _lock; // mutex protecting _bm; | |
82 | |
83 public: | |
84 // constructor | |
85 CMSBitMap(int shifter, int mutex_rank, const char* mutex_name); | |
86 | |
87 // allocates the actual storage for the map | |
88 bool allocate(MemRegion mr); | |
89 // field getter | |
90 Mutex* lock() const { return _lock; } | |
91 // locking verifier convenience function | |
92 void assert_locked() const PRODUCT_RETURN; | |
93 | |
94 // inquiries | |
95 HeapWord* startWord() const { return _bmStartWord; } | |
96 size_t sizeInWords() const { return _bmWordSize; } | |
97 size_t sizeInBits() const { return _bm.size(); } | |
98 // the following is one past the last word in space | |
99 HeapWord* endWord() const { return _bmStartWord + _bmWordSize; } | |
100 | |
101 // reading marks | |
102 bool isMarked(HeapWord* addr) const; | |
103 bool par_isMarked(HeapWord* addr) const; // do not lock checks | |
104 bool isUnmarked(HeapWord* addr) const; | |
105 bool isAllClear() const; | |
106 | |
107 // writing marks | |
108 void mark(HeapWord* addr); | |
109 // For marking by parallel GC threads; | |
110 // returns true if we did, false if another thread did | |
111 bool par_mark(HeapWord* addr); | |
112 | |
113 void mark_range(MemRegion mr); | |
114 void par_mark_range(MemRegion mr); | |
115 void mark_large_range(MemRegion mr); | |
116 void par_mark_large_range(MemRegion mr); | |
117 void par_clear(HeapWord* addr); // For unmarking by parallel GC threads. | |
118 void clear_range(MemRegion mr); | |
119 void par_clear_range(MemRegion mr); | |
120 void clear_large_range(MemRegion mr); | |
121 void par_clear_large_range(MemRegion mr); | |
122 void clear_all(); | |
123 void clear_all_incrementally(); // Not yet implemented!! | |
124 | |
125 NOT_PRODUCT( | |
126 // checks the memory region for validity | |
127 void region_invariant(MemRegion mr); | |
128 ) | |
129 | |
130 // iteration | |
131 void iterate(BitMapClosure* cl) { | |
132 _bm.iterate(cl); | |
133 } | |
134 void iterate(BitMapClosure* cl, HeapWord* left, HeapWord* right); | |
135 void dirty_range_iterate_clear(MemRegionClosure* cl); | |
136 void dirty_range_iterate_clear(MemRegion mr, MemRegionClosure* cl); | |
137 | |
138 // auxiliary support for iteration | |
139 HeapWord* getNextMarkedWordAddress(HeapWord* addr) const; | |
140 HeapWord* getNextMarkedWordAddress(HeapWord* start_addr, | |
141 HeapWord* end_addr) const; | |
142 HeapWord* getNextUnmarkedWordAddress(HeapWord* addr) const; | |
143 HeapWord* getNextUnmarkedWordAddress(HeapWord* start_addr, | |
144 HeapWord* end_addr) const; | |
145 MemRegion getAndClearMarkedRegion(HeapWord* addr); | |
146 MemRegion getAndClearMarkedRegion(HeapWord* start_addr, | |
147 HeapWord* end_addr); | |
148 | |
149 // conversion utilities | |
150 HeapWord* offsetToHeapWord(size_t offset) const; | |
151 size_t heapWordToOffset(HeapWord* addr) const; | |
152 size_t heapWordDiffToOffsetDiff(size_t diff) const; | |
153 | |
154 // debugging | |
155 // is this address range covered by the bit-map? | |
156 NOT_PRODUCT( | |
157 bool covers(MemRegion mr) const; | |
158 bool covers(HeapWord* start, size_t size = 0) const; | |
159 ) | |
160 void verifyNoOneBitsInRange(HeapWord* left, HeapWord* right) PRODUCT_RETURN; | |
161 }; | |
162 | |
163 // Represents a marking stack used by the CMS collector. | |
164 // Ideally this should be GrowableArray<> just like MSC's marking stack(s). | |
6197 | 165 class CMSMarkStack: public CHeapObj<mtGC> { |
0 | 166 // |
167 friend class CMSCollector; // to get at expasion stats further below | |
168 // | |
169 | |
170 VirtualSpace _virtual_space; // space for the stack | |
171 oop* _base; // bottom of stack | |
172 size_t _index; // one more than last occupied index | |
173 size_t _capacity; // max #elements | |
174 Mutex _par_lock; // an advisory lock used in case of parallel access | |
175 NOT_PRODUCT(size_t _max_depth;) // max depth plumbed during run | |
176 | |
177 protected: | |
178 size_t _hit_limit; // we hit max stack size limit | |
179 size_t _failed_double; // we failed expansion before hitting limit | |
180 | |
181 public: | |
182 CMSMarkStack(): | |
183 _par_lock(Mutex::event, "CMSMarkStack._par_lock", true), | |
184 _hit_limit(0), | |
185 _failed_double(0) {} | |
186 | |
187 bool allocate(size_t size); | |
188 | |
189 size_t capacity() const { return _capacity; } | |
190 | |
191 oop pop() { | |
192 if (!isEmpty()) { | |
193 return _base[--_index] ; | |
194 } | |
195 return NULL; | |
196 } | |
197 | |
198 bool push(oop ptr) { | |
199 if (isFull()) { | |
200 return false; | |
201 } else { | |
202 _base[_index++] = ptr; | |
203 NOT_PRODUCT(_max_depth = MAX2(_max_depth, _index)); | |
204 return true; | |
205 } | |
206 } | |
207 | |
208 bool isEmpty() const { return _index == 0; } | |
209 bool isFull() const { | |
210 assert(_index <= _capacity, "buffer overflow"); | |
211 return _index == _capacity; | |
212 } | |
213 | |
214 size_t length() { return _index; } | |
215 | |
216 // "Parallel versions" of some of the above | |
217 oop par_pop() { | |
218 // lock and pop | |
219 MutexLockerEx x(&_par_lock, Mutex::_no_safepoint_check_flag); | |
220 return pop(); | |
221 } | |
222 | |
223 bool par_push(oop ptr) { | |
224 // lock and push | |
225 MutexLockerEx x(&_par_lock, Mutex::_no_safepoint_check_flag); | |
226 return push(ptr); | |
227 } | |
228 | |
229 // Forcibly reset the stack, losing all of its contents. | |
230 void reset() { | |
231 _index = 0; | |
232 } | |
233 | |
234 // Expand the stack, typically in response to an overflow condition | |
235 void expand(); | |
236 | |
237 // Compute the least valued stack element. | |
238 oop least_value(HeapWord* low) { | |
239 oop least = (oop)low; | |
240 for (size_t i = 0; i < _index; i++) { | |
241 least = MIN2(least, _base[i]); | |
242 } | |
243 return least; | |
244 } | |
245 | |
246 // Exposed here to allow stack expansion in || case | |
247 Mutex* par_lock() { return &_par_lock; } | |
248 }; | |
249 | |
250 class CardTableRS; | |
251 class CMSParGCThreadState; | |
252 | |
253 class ModUnionClosure: public MemRegionClosure { | |
254 protected: | |
255 CMSBitMap* _t; | |
256 public: | |
257 ModUnionClosure(CMSBitMap* t): _t(t) { } | |
258 void do_MemRegion(MemRegion mr); | |
259 }; | |
260 | |
261 class ModUnionClosurePar: public ModUnionClosure { | |
262 public: | |
263 ModUnionClosurePar(CMSBitMap* t): ModUnionClosure(t) { } | |
264 void do_MemRegion(MemRegion mr); | |
265 }; | |
266 | |
267 // Survivor Chunk Array in support of parallelization of | |
268 // Survivor Space rescan. | |
6197 | 269 class ChunkArray: public CHeapObj<mtGC> { |
0 | 270 size_t _index; |
271 size_t _capacity; | |
1753
bba76f745fe6
6910183: CMS: assert(_index < capacity(),"_index out of bounds")
ysr
parents:
1716
diff
changeset
|
272 size_t _overflows; |
0 | 273 HeapWord** _array; // storage for array |
274 | |
275 public: | |
1753
bba76f745fe6
6910183: CMS: assert(_index < capacity(),"_index out of bounds")
ysr
parents:
1716
diff
changeset
|
276 ChunkArray() : _index(0), _capacity(0), _overflows(0), _array(NULL) {} |
0 | 277 ChunkArray(HeapWord** a, size_t c): |
1753
bba76f745fe6
6910183: CMS: assert(_index < capacity(),"_index out of bounds")
ysr
parents:
1716
diff
changeset
|
278 _index(0), _capacity(c), _overflows(0), _array(a) {} |
0 | 279 |
280 HeapWord** array() { return _array; } | |
281 void set_array(HeapWord** a) { _array = a; } | |
282 | |
283 size_t capacity() { return _capacity; } | |
284 void set_capacity(size_t c) { _capacity = c; } | |
285 | |
286 size_t end() { | |
1753
bba76f745fe6
6910183: CMS: assert(_index < capacity(),"_index out of bounds")
ysr
parents:
1716
diff
changeset
|
287 assert(_index <= capacity(), |
bba76f745fe6
6910183: CMS: assert(_index < capacity(),"_index out of bounds")
ysr
parents:
1716
diff
changeset
|
288 err_msg("_index (" SIZE_FORMAT ") > _capacity (" SIZE_FORMAT "): out of bounds", |
bba76f745fe6
6910183: CMS: assert(_index < capacity(),"_index out of bounds")
ysr
parents:
1716
diff
changeset
|
289 _index, _capacity)); |
0 | 290 return _index; |
291 } // exclusive | |
292 | |
293 HeapWord* nth(size_t n) { | |
294 assert(n < end(), "Out of bounds access"); | |
295 return _array[n]; | |
296 } | |
297 | |
298 void reset() { | |
299 _index = 0; | |
1753
bba76f745fe6
6910183: CMS: assert(_index < capacity(),"_index out of bounds")
ysr
parents:
1716
diff
changeset
|
300 if (_overflows > 0 && PrintCMSStatistics > 1) { |
bba76f745fe6
6910183: CMS: assert(_index < capacity(),"_index out of bounds")
ysr
parents:
1716
diff
changeset
|
301 warning("CMS: ChunkArray[" SIZE_FORMAT "] overflowed " SIZE_FORMAT " times", |
bba76f745fe6
6910183: CMS: assert(_index < capacity(),"_index out of bounds")
ysr
parents:
1716
diff
changeset
|
302 _capacity, _overflows); |
bba76f745fe6
6910183: CMS: assert(_index < capacity(),"_index out of bounds")
ysr
parents:
1716
diff
changeset
|
303 } |
bba76f745fe6
6910183: CMS: assert(_index < capacity(),"_index out of bounds")
ysr
parents:
1716
diff
changeset
|
304 _overflows = 0; |
0 | 305 } |
306 | |
307 void record_sample(HeapWord* p, size_t sz) { | |
308 // For now we do not do anything with the size | |
309 if (_index < _capacity) { | |
310 _array[_index++] = p; | |
1753
bba76f745fe6
6910183: CMS: assert(_index < capacity(),"_index out of bounds")
ysr
parents:
1716
diff
changeset
|
311 } else { |
bba76f745fe6
6910183: CMS: assert(_index < capacity(),"_index out of bounds")
ysr
parents:
1716
diff
changeset
|
312 ++_overflows; |
bba76f745fe6
6910183: CMS: assert(_index < capacity(),"_index out of bounds")
ysr
parents:
1716
diff
changeset
|
313 assert(_index == _capacity, |
bba76f745fe6
6910183: CMS: assert(_index < capacity(),"_index out of bounds")
ysr
parents:
1716
diff
changeset
|
314 err_msg("_index (" SIZE_FORMAT ") > _capacity (" SIZE_FORMAT |
bba76f745fe6
6910183: CMS: assert(_index < capacity(),"_index out of bounds")
ysr
parents:
1716
diff
changeset
|
315 "): out of bounds at overflow#" SIZE_FORMAT, |
bba76f745fe6
6910183: CMS: assert(_index < capacity(),"_index out of bounds")
ysr
parents:
1716
diff
changeset
|
316 _index, _capacity, _overflows)); |
0 | 317 } |
318 } | |
319 }; | |
320 | |
321 // | |
322 // Timing, allocation and promotion statistics for gc scheduling and incremental | |
323 // mode pacing. Most statistics are exponential averages. | |
324 // | |
325 class CMSStats VALUE_OBJ_CLASS_SPEC { | |
326 private: | |
327 ConcurrentMarkSweepGeneration* const _cms_gen; // The cms (old) gen. | |
328 | |
329 // The following are exponential averages with factor alpha: | |
330 // avg = (100 - alpha) * avg + alpha * cur_sample | |
331 // | |
332 // The durations measure: end_time[n] - start_time[n] | |
333 // The periods measure: start_time[n] - start_time[n-1] | |
334 // | |
335 // The cms period and duration include only concurrent collections; time spent | |
336 // in foreground cms collections due to System.gc() or because of a failure to | |
337 // keep up are not included. | |
338 // | |
339 // There are 3 alphas to "bootstrap" the statistics. The _saved_alpha is the | |
340 // real value, but is used only after the first period. A value of 100 is | |
341 // used for the first sample so it gets the entire weight. | |
342 unsigned int _saved_alpha; // 0-100 | |
343 unsigned int _gc0_alpha; | |
344 unsigned int _cms_alpha; | |
345 | |
346 double _gc0_duration; | |
347 double _gc0_period; | |
348 size_t _gc0_promoted; // bytes promoted per gc0 | |
349 double _cms_duration; | |
350 double _cms_duration_pre_sweep; // time from initiation to start of sweep | |
351 double _cms_duration_per_mb; | |
352 double _cms_period; | |
353 size_t _cms_allocated; // bytes of direct allocation per gc0 period | |
354 | |
355 // Timers. | |
356 elapsedTimer _cms_timer; | |
357 TimeStamp _gc0_begin_time; | |
358 TimeStamp _cms_begin_time; | |
359 TimeStamp _cms_end_time; | |
360 | |
361 // Snapshots of the amount used in the CMS generation. | |
362 size_t _cms_used_at_gc0_begin; | |
363 size_t _cms_used_at_gc0_end; | |
364 size_t _cms_used_at_cms_begin; | |
365 | |
366 // Used to prevent the duty cycle from being reduced in the middle of a cms | |
367 // cycle. | |
368 bool _allow_duty_cycle_reduction; | |
369 | |
370 enum { | |
371 _GC0_VALID = 0x1, | |
372 _CMS_VALID = 0x2, | |
373 _ALL_VALID = _GC0_VALID | _CMS_VALID | |
374 }; | |
375 | |
376 unsigned int _valid_bits; | |
377 | |
378 unsigned int _icms_duty_cycle; // icms duty cycle (0-100). | |
379 | |
380 protected: | |
381 | |
382 // Return a duty cycle that avoids wild oscillations, by limiting the amount | |
383 // of change between old_duty_cycle and new_duty_cycle (the latter is treated | |
384 // as a recommended value). | |
385 static unsigned int icms_damped_duty_cycle(unsigned int old_duty_cycle, | |
386 unsigned int new_duty_cycle); | |
387 unsigned int icms_update_duty_cycle_impl(); | |
388 | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
935
diff
changeset
|
389 // In support of adjusting of cms trigger ratios based on history |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
935
diff
changeset
|
390 // of concurrent mode failure. |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
935
diff
changeset
|
391 double cms_free_adjustment_factor(size_t free) const; |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
935
diff
changeset
|
392 void adjust_cms_free_adjustment_factor(bool fail, size_t free); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
935
diff
changeset
|
393 |
0 | 394 public: |
395 CMSStats(ConcurrentMarkSweepGeneration* cms_gen, | |
396 unsigned int alpha = CMSExpAvgFactor); | |
397 | |
398 // Whether or not the statistics contain valid data; higher level statistics | |
399 // cannot be called until this returns true (they require at least one young | |
400 // gen and one cms cycle to have completed). | |
401 bool valid() const; | |
402 | |
403 // Record statistics. | |
404 void record_gc0_begin(); | |
405 void record_gc0_end(size_t cms_gen_bytes_used); | |
406 void record_cms_begin(); | |
407 void record_cms_end(); | |
408 | |
409 // Allow management of the cms timer, which must be stopped/started around | |
410 // yield points. | |
411 elapsedTimer& cms_timer() { return _cms_timer; } | |
412 void start_cms_timer() { _cms_timer.start(); } | |
413 void stop_cms_timer() { _cms_timer.stop(); } | |
414 | |
415 // Basic statistics; units are seconds or bytes. | |
416 double gc0_period() const { return _gc0_period; } | |
417 double gc0_duration() const { return _gc0_duration; } | |
418 size_t gc0_promoted() const { return _gc0_promoted; } | |
419 double cms_period() const { return _cms_period; } | |
420 double cms_duration() const { return _cms_duration; } | |
421 double cms_duration_per_mb() const { return _cms_duration_per_mb; } | |
422 size_t cms_allocated() const { return _cms_allocated; } | |
423 | |
424 size_t cms_used_at_gc0_end() const { return _cms_used_at_gc0_end;} | |
425 | |
426 // Seconds since the last background cms cycle began or ended. | |
427 double cms_time_since_begin() const; | |
428 double cms_time_since_end() const; | |
429 | |
430 // Higher level statistics--caller must check that valid() returns true before | |
431 // calling. | |
432 | |
433 // Returns bytes promoted per second of wall clock time. | |
434 double promotion_rate() const; | |
435 | |
436 // Returns bytes directly allocated per second of wall clock time. | |
437 double cms_allocation_rate() const; | |
438 | |
439 // Rate at which space in the cms generation is being consumed (sum of the | |
440 // above two). | |
441 double cms_consumption_rate() const; | |
442 | |
443 // Returns an estimate of the number of seconds until the cms generation will | |
444 // fill up, assuming no collection work is done. | |
445 double time_until_cms_gen_full() const; | |
446 | |
447 // Returns an estimate of the number of seconds remaining until | |
448 // the cms generation collection should start. | |
449 double time_until_cms_start() const; | |
450 | |
451 // End of higher level statistics. | |
452 | |
453 // Returns the cms incremental mode duty cycle, as a percentage (0-100). | |
454 unsigned int icms_duty_cycle() const { return _icms_duty_cycle; } | |
455 | |
456 // Update the duty cycle and return the new value. | |
457 unsigned int icms_update_duty_cycle(); | |
458 | |
459 // Debugging. | |
460 void print_on(outputStream* st) const PRODUCT_RETURN; | |
461 void print() const { print_on(gclog_or_tty); } | |
462 }; | |
463 | |
464 // A closure related to weak references processing which | |
465 // we embed in the CMSCollector, since we need to pass | |
466 // it to the reference processor for secondary filtering | |
467 // of references based on reachability of referent; | |
468 // see role of _is_alive_non_header closure in the | |
469 // ReferenceProcessor class. | |
470 // For objects in the CMS generation, this closure checks | |
471 // if the object is "live" (reachable). Used in weak | |
472 // reference processing. | |
473 class CMSIsAliveClosure: public BoolObjectClosure { | |
143
b5489bb705c9
6662086: 6u4+, 7b11+: CMS never clears referents when -XX:+ParallelRefProcEnabled
ysr
parents:
113
diff
changeset
|
474 const MemRegion _span; |
0 | 475 const CMSBitMap* _bit_map; |
476 | |
477 friend class CMSCollector; | |
478 public: | |
479 CMSIsAliveClosure(MemRegion span, | |
480 CMSBitMap* bit_map): | |
481 _span(span), | |
143
b5489bb705c9
6662086: 6u4+, 7b11+: CMS never clears referents when -XX:+ParallelRefProcEnabled
ysr
parents:
113
diff
changeset
|
482 _bit_map(bit_map) { |
b5489bb705c9
6662086: 6u4+, 7b11+: CMS never clears referents when -XX:+ParallelRefProcEnabled
ysr
parents:
113
diff
changeset
|
483 assert(!span.is_empty(), "Empty span could spell trouble"); |
b5489bb705c9
6662086: 6u4+, 7b11+: CMS never clears referents when -XX:+ParallelRefProcEnabled
ysr
parents:
113
diff
changeset
|
484 } |
b5489bb705c9
6662086: 6u4+, 7b11+: CMS never clears referents when -XX:+ParallelRefProcEnabled
ysr
parents:
113
diff
changeset
|
485 |
0 | 486 void do_object(oop obj) { |
487 assert(false, "not to be invoked"); | |
488 } | |
143
b5489bb705c9
6662086: 6u4+, 7b11+: CMS never clears referents when -XX:+ParallelRefProcEnabled
ysr
parents:
113
diff
changeset
|
489 |
0 | 490 bool do_object_b(oop obj); |
491 }; | |
492 | |
493 | |
494 // Implements AbstractRefProcTaskExecutor for CMS. | |
495 class CMSRefProcTaskExecutor: public AbstractRefProcTaskExecutor { | |
496 public: | |
497 | |
498 CMSRefProcTaskExecutor(CMSCollector& collector) | |
499 : _collector(collector) | |
500 { } | |
501 | |
502 // Executes a task using worker threads. | |
503 virtual void execute(ProcessTask& task); | |
504 virtual void execute(EnqueueTask& task); | |
505 private: | |
506 CMSCollector& _collector; | |
507 }; | |
508 | |
509 | |
6197 | 510 class CMSCollector: public CHeapObj<mtGC> { |
0 | 511 friend class VMStructs; |
512 friend class ConcurrentMarkSweepThread; | |
513 friend class ConcurrentMarkSweepGeneration; | |
514 friend class CompactibleFreeListSpace; | |
515 friend class CMSParRemarkTask; | |
516 friend class CMSConcMarkingTask; | |
517 friend class CMSRefProcTaskProxy; | |
518 friend class CMSRefProcTaskExecutor; | |
519 friend class ScanMarkedObjectsAgainCarefullyClosure; // for sampling eden | |
520 friend class SurvivorSpacePrecleanClosure; // --- ditto ------- | |
521 friend class PushOrMarkClosure; // to access _restart_addr | |
522 friend class Par_PushOrMarkClosure; // to access _restart_addr | |
523 friend class MarkFromRootsClosure; // -- ditto -- | |
524 // ... and for clearing cards | |
525 friend class Par_MarkFromRootsClosure; // to access _restart_addr | |
526 // ... and for clearing cards | |
527 friend class Par_ConcMarkingClosure; // to access _restart_addr etc. | |
528 friend class MarkFromRootsVerifyClosure; // to access _restart_addr | |
529 friend class PushAndMarkVerifyClosure; // -- ditto -- | |
530 friend class MarkRefsIntoAndScanClosure; // to access _overflow_list | |
531 friend class PushAndMarkClosure; // -- ditto -- | |
532 friend class Par_PushAndMarkClosure; // -- ditto -- | |
533 friend class CMSKeepAliveClosure; // -- ditto -- | |
534 friend class CMSDrainMarkingStackClosure; // -- ditto -- | |
535 friend class CMSInnerParMarkAndPushClosure; // -- ditto -- | |
536 NOT_PRODUCT(friend class ScanMarkedObjectsAgainClosure;) // assertion on _overflow_list | |
537 friend class ReleaseForegroundGC; // to access _foregroundGCShouldWait | |
538 friend class VM_CMS_Operation; | |
539 friend class VM_CMS_Initial_Mark; | |
540 friend class VM_CMS_Final_Remark; | |
1703
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1552
diff
changeset
|
541 friend class TraceCMSMemoryManagerStats; |
0 | 542 |
543 private: | |
544 jlong _time_of_last_gc; | |
545 void update_time_of_last_gc(jlong now) { | |
546 _time_of_last_gc = now; | |
547 } | |
548 | |
549 OopTaskQueueSet* _task_queues; | |
550 | |
551 // Overflow list of grey objects, threaded through mark-word | |
552 // Manipulated with CAS in the parallel/multi-threaded case. | |
553 oop _overflow_list; | |
554 // The following array-pair keeps track of mark words | |
555 // displaced for accomodating overflow list above. | |
556 // This code will likely be revisited under RFE#4922830. | |
6197 | 557 Stack<oop, mtGC> _preserved_oop_stack; |
558 Stack<markOop, mtGC> _preserved_mark_stack; | |
0 | 559 |
560 int* _hash_seed; | |
561 | |
562 // In support of multi-threaded concurrent phases | |
563 YieldingFlexibleWorkGang* _conc_workers; | |
564 | |
565 // Performance Counters | |
566 CollectorCounters* _gc_counters; | |
567 | |
568 // Initialization Errors | |
569 bool _completed_initialization; | |
570 | |
571 // In support of ExplicitGCInvokesConcurrent | |
572 static bool _full_gc_requested; | |
573 unsigned int _collection_count_start; | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
0
diff
changeset
|
574 |
0 | 575 // Should we unload classes this concurrent cycle? |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
0
diff
changeset
|
576 bool _should_unload_classes; |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
0
diff
changeset
|
577 unsigned int _concurrent_cycles_since_last_unload; |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
0
diff
changeset
|
578 unsigned int concurrent_cycles_since_last_unload() const { |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
0
diff
changeset
|
579 return _concurrent_cycles_since_last_unload; |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
0
diff
changeset
|
580 } |
0 | 581 // Did we (allow) unload classes in the previous concurrent cycle? |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
0
diff
changeset
|
582 bool unloaded_classes_last_cycle() const { |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
0
diff
changeset
|
583 return concurrent_cycles_since_last_unload() == 0; |
0 | 584 } |
798
fe1574da39fc
6848641: CMSCollector::_roots_scanning_options should be initialized
ysr
parents:
579
diff
changeset
|
585 // Root scanning options for perm gen |
fe1574da39fc
6848641: CMSCollector::_roots_scanning_options should be initialized
ysr
parents:
579
diff
changeset
|
586 int _roots_scanning_options; |
fe1574da39fc
6848641: CMSCollector::_roots_scanning_options should be initialized
ysr
parents:
579
diff
changeset
|
587 int roots_scanning_options() const { return _roots_scanning_options; } |
fe1574da39fc
6848641: CMSCollector::_roots_scanning_options should be initialized
ysr
parents:
579
diff
changeset
|
588 void add_root_scanning_option(int o) { _roots_scanning_options |= o; } |
fe1574da39fc
6848641: CMSCollector::_roots_scanning_options should be initialized
ysr
parents:
579
diff
changeset
|
589 void remove_root_scanning_option(int o) { _roots_scanning_options &= ~o; } |
0 | 590 |
591 // Verification support | |
592 CMSBitMap _verification_mark_bm; | |
593 void verify_after_remark_work_1(); | |
594 void verify_after_remark_work_2(); | |
595 | |
596 // true if any verification flag is on. | |
597 bool _verifying; | |
598 bool verifying() const { return _verifying; } | |
599 void set_verifying(bool v) { _verifying = v; } | |
600 | |
601 // Collector policy | |
602 ConcurrentMarkSweepPolicy* _collector_policy; | |
603 ConcurrentMarkSweepPolicy* collector_policy() { return _collector_policy; } | |
604 | |
605 // XXX Move these to CMSStats ??? FIX ME !!! | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
935
diff
changeset
|
606 elapsedTimer _inter_sweep_timer; // time between sweeps |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
935
diff
changeset
|
607 elapsedTimer _intra_sweep_timer; // time _in_ sweeps |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
935
diff
changeset
|
608 // padded decaying average estimates of the above |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
935
diff
changeset
|
609 AdaptivePaddedAverage _inter_sweep_estimate; |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
935
diff
changeset
|
610 AdaptivePaddedAverage _intra_sweep_estimate; |
0 | 611 |
612 protected: | |
613 ConcurrentMarkSweepGeneration* _cmsGen; // old gen (CMS) | |
614 MemRegion _span; // span covering above two | |
615 CardTableRS* _ct; // card table | |
616 | |
617 // CMS marking support structures | |
618 CMSBitMap _markBitMap; | |
619 CMSBitMap _modUnionTable; | |
620 CMSMarkStack _markStack; | |
621 | |
622 HeapWord* _restart_addr; // in support of marking stack overflow | |
623 void lower_restart_addr(HeapWord* low); | |
624 | |
625 // Counters in support of marking stack / work queue overflow handling: | |
626 // a non-zero value indicates certain types of overflow events during | |
627 // the current CMS cycle and could lead to stack resizing efforts at | |
628 // an opportune future time. | |
629 size_t _ser_pmc_preclean_ovflw; | |
630 size_t _ser_pmc_remark_ovflw; | |
631 size_t _par_pmc_remark_ovflw; | |
452
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
356
diff
changeset
|
632 size_t _ser_kac_preclean_ovflw; |
0 | 633 size_t _ser_kac_ovflw; |
634 size_t _par_kac_ovflw; | |
534 | 635 NOT_PRODUCT(ssize_t _num_par_pushes;) |
0 | 636 |
637 // ("Weak") Reference processing support | |
638 ReferenceProcessor* _ref_processor; | |
639 CMSIsAliveClosure _is_alive_closure; | |
143
b5489bb705c9
6662086: 6u4+, 7b11+: CMS never clears referents when -XX:+ParallelRefProcEnabled
ysr
parents:
113
diff
changeset
|
640 // keep this textually after _markBitMap and _span; c'tor dependency |
0 | 641 |
642 ConcurrentMarkSweepThread* _cmsThread; // the thread doing the work | |
643 ModUnionClosure _modUnionClosure; | |
644 ModUnionClosurePar _modUnionClosurePar; | |
645 | |
646 // CMS abstract state machine | |
647 // initial_state: Idling | |
648 // next_state(Idling) = {Marking} | |
649 // next_state(Marking) = {Precleaning, Sweeping} | |
650 // next_state(Precleaning) = {AbortablePreclean, FinalMarking} | |
651 // next_state(AbortablePreclean) = {FinalMarking} | |
652 // next_state(FinalMarking) = {Sweeping} | |
653 // next_state(Sweeping) = {Resizing} | |
654 // next_state(Resizing) = {Resetting} | |
655 // next_state(Resetting) = {Idling} | |
656 // The numeric values below are chosen so that: | |
657 // . _collectorState <= Idling == post-sweep && pre-mark | |
658 // . _collectorState in (Idling, Sweeping) == {initial,final}marking || | |
659 // precleaning || abortablePrecleanb | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
935
diff
changeset
|
660 public: |
0 | 661 enum CollectorState { |
662 Resizing = 0, | |
663 Resetting = 1, | |
664 Idling = 2, | |
665 InitialMarking = 3, | |
666 Marking = 4, | |
667 Precleaning = 5, | |
668 AbortablePreclean = 6, | |
669 FinalMarking = 7, | |
670 Sweeping = 8 | |
671 }; | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
935
diff
changeset
|
672 protected: |
0 | 673 static CollectorState _collectorState; |
674 | |
675 // State related to prologue/epilogue invocation for my generations | |
676 bool _between_prologue_and_epilogue; | |
677 | |
678 // Signalling/State related to coordination between fore- and backgroud GC | |
679 // Note: When the baton has been passed from background GC to foreground GC, | |
680 // _foregroundGCIsActive is true and _foregroundGCShouldWait is false. | |
681 static bool _foregroundGCIsActive; // true iff foreground collector is active or | |
682 // wants to go active | |
683 static bool _foregroundGCShouldWait; // true iff background GC is active and has not | |
684 // yet passed the baton to the foreground GC | |
685 | |
686 // Support for CMSScheduleRemark (abortable preclean) | |
687 bool _abort_preclean; | |
688 bool _start_sampling; | |
689 | |
690 int _numYields; | |
691 size_t _numDirtyCards; | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
935
diff
changeset
|
692 size_t _sweep_count; |
0 | 693 // number of full gc's since the last concurrent gc. |
694 uint _full_gcs_since_conc_gc; | |
695 | |
696 // occupancy used for bootstrapping stats | |
697 double _bootstrap_occupancy; | |
698 | |
699 // timer | |
700 elapsedTimer _timer; | |
701 | |
702 // Timing, allocation and promotion statistics, used for scheduling. | |
703 CMSStats _stats; | |
704 | |
705 // Allocation limits installed in the young gen, used only in | |
706 // CMSIncrementalMode. When an allocation in the young gen would cross one of | |
707 // these limits, the cms generation is notified and the cms thread is started | |
708 // or stopped, respectively. | |
709 HeapWord* _icms_start_limit; | |
710 HeapWord* _icms_stop_limit; | |
711 | |
712 enum CMS_op_type { | |
713 CMS_op_checkpointRootsInitial, | |
714 CMS_op_checkpointRootsFinal | |
715 }; | |
716 | |
6064
9d679effd28c
7166894: Add gc cause to GC logging for all collectors
brutisso
parents:
6026
diff
changeset
|
717 void do_CMS_operation(CMS_op_type op, GCCause::Cause gc_cause); |
0 | 718 bool stop_world_and_do(CMS_op_type op); |
719 | |
720 OopTaskQueueSet* task_queues() { return _task_queues; } | |
721 int* hash_seed(int i) { return &_hash_seed[i]; } | |
722 YieldingFlexibleWorkGang* conc_workers() { return _conc_workers; } | |
723 | |
724 // Support for parallelizing Eden rescan in CMS remark phase | |
725 void sample_eden(); // ... sample Eden space top | |
726 | |
727 private: | |
728 // Support for parallelizing young gen rescan in CMS remark phase | |
729 Generation* _young_gen; // the younger gen | |
730 HeapWord** _top_addr; // ... Top of Eden | |
731 HeapWord** _end_addr; // ... End of Eden | |
732 HeapWord** _eden_chunk_array; // ... Eden partitioning array | |
733 size_t _eden_chunk_index; // ... top (exclusive) of array | |
734 size_t _eden_chunk_capacity; // ... max entries in array | |
735 | |
736 // Support for parallelizing survivor space rescan | |
737 HeapWord** _survivor_chunk_array; | |
738 size_t _survivor_chunk_index; | |
739 size_t _survivor_chunk_capacity; | |
740 size_t* _cursor; | |
741 ChunkArray* _survivor_plab_array; | |
742 | |
743 // Support for marking stack overflow handling | |
744 bool take_from_overflow_list(size_t num, CMSMarkStack* to_stack); | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1753
diff
changeset
|
745 bool par_take_from_overflow_list(size_t num, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1753
diff
changeset
|
746 OopTaskQueue* to_work_q, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1753
diff
changeset
|
747 int no_of_gc_threads); |
0 | 748 void push_on_overflow_list(oop p); |
749 void par_push_on_overflow_list(oop p); | |
750 // the following is, obviously, not, in general, "MT-stable" | |
751 bool overflow_list_is_empty() const; | |
752 | |
753 void preserve_mark_if_necessary(oop p); | |
754 void par_preserve_mark_if_necessary(oop p); | |
755 void preserve_mark_work(oop p, markOop m); | |
756 void restore_preserved_marks_if_any(); | |
757 NOT_PRODUCT(bool no_preserved_marks() const;) | |
758 // in support of testing overflow code | |
759 NOT_PRODUCT(int _overflow_counter;) | |
760 NOT_PRODUCT(bool simulate_overflow();) // sequential | |
761 NOT_PRODUCT(bool par_simulate_overflow();) // MT version | |
762 | |
763 // CMS work methods | |
764 void checkpointRootsInitialWork(bool asynch); // initial checkpoint work | |
765 | |
766 // a return value of false indicates failure due to stack overflow | |
767 bool markFromRootsWork(bool asynch); // concurrent marking work | |
768 | |
769 public: // FIX ME!!! only for testing | |
770 bool do_marking_st(bool asynch); // single-threaded marking | |
771 bool do_marking_mt(bool asynch); // multi-threaded marking | |
772 | |
773 private: | |
774 | |
775 // concurrent precleaning work | |
776 size_t preclean_mod_union_table(ConcurrentMarkSweepGeneration* gen, | |
777 ScanMarkedObjectsAgainCarefullyClosure* cl); | |
778 size_t preclean_card_table(ConcurrentMarkSweepGeneration* gen, | |
779 ScanMarkedObjectsAgainCarefullyClosure* cl); | |
780 // Does precleaning work, returning a quantity indicative of | |
781 // the amount of "useful work" done. | |
782 size_t preclean_work(bool clean_refs, bool clean_survivors); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
783 void preclean_klasses(MarkRefsIntoAndScanClosure* cl, Mutex* freelistLock); |
0 | 784 void abortable_preclean(); // Preclean while looking for possible abort |
785 void initialize_sequential_subtasks_for_young_gen_rescan(int i); | |
786 // Helper function for above; merge-sorts the per-thread plab samples | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1753
diff
changeset
|
787 void merge_survivor_plab_arrays(ContiguousSpace* surv, int no_of_gc_threads); |
0 | 788 // Resets (i.e. clears) the per-thread plab sample vectors |
789 void reset_survivor_plab_arrays(); | |
790 | |
791 // final (second) checkpoint work | |
792 void checkpointRootsFinalWork(bool asynch, bool clear_all_soft_refs, | |
793 bool init_mark_was_synchronous); | |
794 // work routine for parallel version of remark | |
795 void do_remark_parallel(); | |
796 // work routine for non-parallel version of remark | |
797 void do_remark_non_parallel(); | |
798 // reference processing work routine (during second checkpoint) | |
799 void refProcessingWork(bool asynch, bool clear_all_soft_refs); | |
800 | |
801 // concurrent sweeping work | |
802 void sweepWork(ConcurrentMarkSweepGeneration* gen, bool asynch); | |
803 | |
804 // (concurrent) resetting of support data structures | |
805 void reset(bool asynch); | |
806 | |
807 // Clear _expansion_cause fields of constituent generations | |
808 void clear_expansion_cause(); | |
809 | |
810 // An auxilliary method used to record the ends of | |
811 // used regions of each generation to limit the extent of sweep | |
812 void save_sweep_limits(); | |
813 | |
814 // A work method used by foreground collection to determine | |
815 // what type of collection (compacting or not, continuing or fresh) | |
816 // it should do. | |
817 void decide_foreground_collection_type(bool clear_all_soft_refs, | |
818 bool* should_compact, bool* should_start_over); | |
819 | |
820 // A work method used by the foreground collector to do | |
821 // a mark-sweep-compact. | |
822 void do_compaction_work(bool clear_all_soft_refs); | |
823 | |
824 // A work method used by the foreground collector to do | |
825 // a mark-sweep, after taking over from a possibly on-going | |
826 // concurrent mark-sweep collection. | |
827 void do_mark_sweep_work(bool clear_all_soft_refs, | |
828 CollectorState first_state, bool should_start_over); | |
829 | |
830 // If the backgrould GC is active, acquire control from the background | |
831 // GC and do the collection. | |
832 void acquire_control_and_collect(bool full, bool clear_all_soft_refs); | |
833 | |
834 // For synchronizing passing of control from background to foreground | |
835 // GC. waitForForegroundGC() is called by the background | |
836 // collector. It if had to wait for a foreground collection, | |
837 // it returns true and the background collection should assume | |
838 // that the collection was finished by the foreground | |
839 // collector. | |
840 bool waitForForegroundGC(); | |
841 | |
842 // Incremental mode triggering: recompute the icms duty cycle and set the | |
843 // allocation limits in the young gen. | |
844 void icms_update_allocation_limits(); | |
845 | |
846 size_t block_size_using_printezis_bits(HeapWord* addr) const; | |
847 size_t block_size_if_printezis_bits(HeapWord* addr) const; | |
848 HeapWord* next_card_start_after_block(HeapWord* addr) const; | |
849 | |
850 void setup_cms_unloading_and_verification_state(); | |
851 public: | |
852 CMSCollector(ConcurrentMarkSweepGeneration* cmsGen, | |
853 CardTableRS* ct, | |
854 ConcurrentMarkSweepPolicy* cp); | |
855 ConcurrentMarkSweepThread* cmsThread() { return _cmsThread; } | |
856 | |
857 ReferenceProcessor* ref_processor() { return _ref_processor; } | |
858 void ref_processor_init(); | |
859 | |
860 Mutex* bitMapLock() const { return _markBitMap.lock(); } | |
861 static CollectorState abstract_state() { return _collectorState; } | |
862 | |
863 bool should_abort_preclean() const; // Whether preclean should be aborted. | |
864 size_t get_eden_used() const; | |
865 size_t get_eden_capacity() const; | |
866 | |
867 ConcurrentMarkSweepGeneration* cmsGen() { return _cmsGen; } | |
868 | |
869 // locking checks | |
870 NOT_PRODUCT(static bool have_cms_token();) | |
871 | |
872 // XXXPERM bool should_collect(bool full, size_t size, bool tlab); | |
873 bool shouldConcurrentCollect(); | |
874 | |
875 void collect(bool full, | |
876 bool clear_all_soft_refs, | |
877 size_t size, | |
878 bool tlab); | |
879 void collect_in_background(bool clear_all_soft_refs); | |
880 void collect_in_foreground(bool clear_all_soft_refs); | |
881 | |
882 // In support of ExplicitGCInvokesConcurrent | |
883 static void request_full_gc(unsigned int full_gc_count); | |
884 // Should we unload classes in a particular concurrent cycle? | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
0
diff
changeset
|
885 bool should_unload_classes() const { |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
0
diff
changeset
|
886 return _should_unload_classes; |
0 | 887 } |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
888 void update_should_unload_classes(); |
0 | 889 |
890 void direct_allocated(HeapWord* start, size_t size); | |
891 | |
892 // Object is dead if not marked and current phase is sweeping. | |
893 bool is_dead_obj(oop obj) const; | |
894 | |
895 // After a promotion (of "start"), do any necessary marking. | |
896 // If "par", then it's being done by a parallel GC thread. | |
897 // The last two args indicate if we need precise marking | |
898 // and if so the size of the object so it can be dirtied | |
899 // in its entirety. | |
900 void promoted(bool par, HeapWord* start, | |
901 bool is_obj_array, size_t obj_size); | |
902 | |
903 HeapWord* allocation_limit_reached(Space* space, HeapWord* top, | |
904 size_t word_size); | |
905 | |
906 void getFreelistLocks() const; | |
907 void releaseFreelistLocks() const; | |
908 bool haveFreelistLocks() const; | |
909 | |
9072
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8035
diff
changeset
|
910 // Adjust size of underlying generation |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8035
diff
changeset
|
911 void compute_new_size(); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8035
diff
changeset
|
912 |
0 | 913 // GC prologue and epilogue |
914 void gc_prologue(bool full); | |
915 void gc_epilogue(bool full); | |
916 | |
917 jlong time_of_last_gc(jlong now) { | |
918 if (_collectorState <= Idling) { | |
919 // gc not in progress | |
920 return _time_of_last_gc; | |
921 } else { | |
922 // collection in progress | |
923 return now; | |
924 } | |
925 } | |
926 | |
927 // Support for parallel remark of survivor space | |
928 void* get_data_recorder(int thr_num); | |
929 | |
930 CMSBitMap* markBitMap() { return &_markBitMap; } | |
931 void directAllocated(HeapWord* start, size_t size); | |
932 | |
933 // main CMS steps and related support | |
934 void checkpointRootsInitial(bool asynch); | |
935 bool markFromRoots(bool asynch); // a return value of false indicates failure | |
936 // due to stack overflow | |
937 void preclean(); | |
938 void checkpointRootsFinal(bool asynch, bool clear_all_soft_refs, | |
939 bool init_mark_was_synchronous); | |
940 void sweep(bool asynch); | |
941 | |
942 // Check that the currently executing thread is the expected | |
943 // one (foreground collector or background collector). | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
935
diff
changeset
|
944 static void check_correct_thread_executing() PRODUCT_RETURN; |
0 | 945 // XXXPERM void print_statistics() PRODUCT_RETURN; |
946 | |
947 bool is_cms_reachable(HeapWord* addr); | |
948 | |
949 // Performance Counter Support | |
950 CollectorCounters* counters() { return _gc_counters; } | |
951 | |
952 // timer stuff | |
953 void startTimer() { assert(!_timer.is_active(), "Error"); _timer.start(); } | |
954 void stopTimer() { assert( _timer.is_active(), "Error"); _timer.stop(); } | |
955 void resetTimer() { assert(!_timer.is_active(), "Error"); _timer.reset(); } | |
956 double timerValue() { assert(!_timer.is_active(), "Error"); return _timer.seconds(); } | |
957 | |
958 int yields() { return _numYields; } | |
959 void resetYields() { _numYields = 0; } | |
960 void incrementYields() { _numYields++; } | |
961 void resetNumDirtyCards() { _numDirtyCards = 0; } | |
962 void incrementNumDirtyCards(size_t num) { _numDirtyCards += num; } | |
963 size_t numDirtyCards() { return _numDirtyCards; } | |
964 | |
965 static bool foregroundGCShouldWait() { return _foregroundGCShouldWait; } | |
966 static void set_foregroundGCShouldWait(bool v) { _foregroundGCShouldWait = v; } | |
967 static bool foregroundGCIsActive() { return _foregroundGCIsActive; } | |
968 static void set_foregroundGCIsActive(bool v) { _foregroundGCIsActive = v; } | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
935
diff
changeset
|
969 size_t sweep_count() const { return _sweep_count; } |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
935
diff
changeset
|
970 void increment_sweep_count() { _sweep_count++; } |
0 | 971 |
972 // Timers/stats for gc scheduling and incremental mode pacing. | |
973 CMSStats& stats() { return _stats; } | |
974 | |
975 // Convenience methods that check whether CMSIncrementalMode is enabled and | |
976 // forward to the corresponding methods in ConcurrentMarkSweepThread. | |
977 static void start_icms(); | |
978 static void stop_icms(); // Called at the end of the cms cycle. | |
979 static void disable_icms(); // Called before a foreground collection. | |
980 static void enable_icms(); // Called after a foreground collection. | |
981 void icms_wait(); // Called at yield points. | |
982 | |
983 // Adaptive size policy | |
984 CMSAdaptiveSizePolicy* size_policy(); | |
985 CMSGCAdaptivePolicyCounters* gc_adaptive_policy_counters(); | |
986 | |
987 // debugging | |
6008 | 988 void verify(); |
0 | 989 bool verify_after_remark(); |
990 void verify_ok_to_terminate() const PRODUCT_RETURN; | |
991 void verify_work_stacks_empty() const PRODUCT_RETURN; | |
992 void verify_overflow_empty() const PRODUCT_RETURN; | |
993 | |
994 // convenience methods in support of debugging | |
995 static const size_t skip_header_HeapWords() PRODUCT_RETURN0; | |
996 HeapWord* block_start(const void* p) const PRODUCT_RETURN0; | |
997 | |
998 // accessors | |
999 CMSMarkStack* verification_mark_stack() { return &_markStack; } | |
1000 CMSBitMap* verification_mark_bm() { return &_verification_mark_bm; } | |
1001 | |
1002 // Initialization errors | |
1003 bool completed_initialization() { return _completed_initialization; } | |
1004 }; | |
1005 | |
1006 class CMSExpansionCause : public AllStatic { | |
1007 public: | |
1008 enum Cause { | |
1009 _no_expansion, | |
1010 _satisfy_free_ratio, | |
1011 _satisfy_promotion, | |
1012 _satisfy_allocation, | |
1013 _allocate_par_lab, | |
1014 _allocate_par_spooling_space, | |
1015 _adaptive_size_policy | |
1016 }; | |
1017 // Return a string describing the cause of the expansion. | |
1018 static const char* to_string(CMSExpansionCause::Cause cause); | |
1019 }; | |
1020 | |
1021 class ConcurrentMarkSweepGeneration: public CardGeneration { | |
1022 friend class VMStructs; | |
1023 friend class ConcurrentMarkSweepThread; | |
1024 friend class ConcurrentMarkSweep; | |
1025 friend class CMSCollector; | |
1026 protected: | |
1027 static CMSCollector* _collector; // the collector that collects us | |
1028 CompactibleFreeListSpace* _cmsSpace; // underlying space (only one for now) | |
1029 | |
1030 // Performance Counters | |
1031 GenerationCounters* _gen_counters; | |
1032 GSpaceCounters* _space_counters; | |
1033 | |
1034 // Words directly allocated, used by CMSStats. | |
1035 size_t _direct_allocated_words; | |
1036 | |
1037 // Non-product stat counters | |
1038 NOT_PRODUCT( | |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1703
diff
changeset
|
1039 size_t _numObjectsPromoted; |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1703
diff
changeset
|
1040 size_t _numWordsPromoted; |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1703
diff
changeset
|
1041 size_t _numObjectsAllocated; |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1703
diff
changeset
|
1042 size_t _numWordsAllocated; |
0 | 1043 ) |
1044 | |
1045 // Used for sizing decisions | |
1046 bool _incremental_collection_failed; | |
1047 bool incremental_collection_failed() { | |
1048 return _incremental_collection_failed; | |
1049 } | |
1050 void set_incremental_collection_failed() { | |
1051 _incremental_collection_failed = true; | |
1052 } | |
1053 void clear_incremental_collection_failed() { | |
1054 _incremental_collection_failed = false; | |
1055 } | |
1056 | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
0
diff
changeset
|
1057 // accessors |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
0
diff
changeset
|
1058 void set_expansion_cause(CMSExpansionCause::Cause v) { _expansion_cause = v;} |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
0
diff
changeset
|
1059 CMSExpansionCause::Cause expansion_cause() const { return _expansion_cause; } |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
0
diff
changeset
|
1060 |
0 | 1061 private: |
1062 // For parallel young-gen GC support. | |
1063 CMSParGCThreadState** _par_gc_thread_states; | |
1064 | |
1065 // Reason generation was expanded | |
1066 CMSExpansionCause::Cause _expansion_cause; | |
1067 | |
1068 // In support of MinChunkSize being larger than min object size | |
1069 const double _dilatation_factor; | |
1070 | |
1071 enum CollectionTypes { | |
1072 Concurrent_collection_type = 0, | |
1073 MS_foreground_collection_type = 1, | |
1074 MSC_foreground_collection_type = 2, | |
1075 Unknown_collection_type = 3 | |
1076 }; | |
1077 | |
1078 CollectionTypes _debug_collection_type; | |
1079 | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
0
diff
changeset
|
1080 // Fraction of current occupancy at which to start a CMS collection which |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
0
diff
changeset
|
1081 // will collect this generation (at least). |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
0
diff
changeset
|
1082 double _initiating_occupancy; |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
0
diff
changeset
|
1083 |
0 | 1084 protected: |
1085 // Shrink generation by specified size (returns false if unable to shrink) | |
9072
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8035
diff
changeset
|
1086 void shrink_free_list_by(size_t bytes); |
0 | 1087 |
1088 // Update statistics for GC | |
1089 virtual void update_gc_stats(int level, bool full); | |
1090 | |
1091 // Maximum available space in the generation (including uncommitted) | |
1092 // space. | |
1093 size_t max_available() const; | |
1094 | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
0
diff
changeset
|
1095 // getter and initializer for _initiating_occupancy field. |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
0
diff
changeset
|
1096 double initiating_occupancy() const { return _initiating_occupancy; } |
8035 | 1097 void init_initiating_occupancy(intx io, uintx tr); |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
0
diff
changeset
|
1098 |
0 | 1099 public: |
1100 ConcurrentMarkSweepGeneration(ReservedSpace rs, size_t initial_byte_size, | |
1101 int level, CardTableRS* ct, | |
1102 bool use_adaptive_freelists, | |
6026 | 1103 FreeBlockDictionary<FreeChunk>::DictionaryChoice); |
0 | 1104 |
1105 // Accessors | |
1106 CMSCollector* collector() const { return _collector; } | |
1107 static void set_collector(CMSCollector* collector) { | |
1108 assert(_collector == NULL, "already set"); | |
1109 _collector = collector; | |
1110 } | |
1111 CompactibleFreeListSpace* cmsSpace() const { return _cmsSpace; } | |
1112 | |
1113 Mutex* freelistLock() const; | |
1114 | |
1115 virtual Generation::Name kind() { return Generation::ConcurrentMarkSweep; } | |
1116 | |
1117 // Adaptive size policy | |
1118 CMSAdaptiveSizePolicy* size_policy(); | |
1119 | |
1120 bool refs_discovery_is_atomic() const { return false; } | |
1121 bool refs_discovery_is_mt() const { | |
1122 // Note: CMS does MT-discovery during the parallel-remark | |
1123 // phases. Use ReferenceProcessorMTMutator to make refs | |
1124 // discovery MT-safe during such phases or other parallel | |
1125 // discovery phases in the future. This may all go away | |
1126 // if/when we decide that refs discovery is sufficiently | |
1127 // rare that the cost of the CAS's involved is in the | |
1128 // noise. That's a measurement that should be done, and | |
1129 // the code simplified if that turns out to be the case. | |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2132
diff
changeset
|
1130 return ConcGCThreads > 1; |
0 | 1131 } |
1132 | |
1133 // Override | |
1134 virtual void ref_processor_init(); | |
1135 | |
271
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
196
diff
changeset
|
1136 // Grow generation by specified size (returns false if unable to grow) |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
196
diff
changeset
|
1137 bool grow_by(size_t bytes); |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
196
diff
changeset
|
1138 // Grow generation to reserved size. |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
196
diff
changeset
|
1139 bool grow_to_reserved(); |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
196
diff
changeset
|
1140 |
0 | 1141 void clear_expansion_cause() { _expansion_cause = CMSExpansionCause::_no_expansion; } |
1142 | |
1143 // Space enquiries | |
1144 size_t capacity() const; | |
1145 size_t used() const; | |
1146 size_t free() const; | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
0
diff
changeset
|
1147 double occupancy() const { return ((double)used())/((double)capacity()); } |
0 | 1148 size_t contiguous_available() const; |
1149 size_t unsafe_max_alloc_nogc() const; | |
1150 | |
1151 // over-rides | |
1152 MemRegion used_region() const; | |
1153 MemRegion used_region_at_save_marks() const; | |
1154 | |
1155 // Does a "full" (forced) collection invoked on this generation collect | |
1156 // all younger generations as well? Note that the second conjunct is a | |
1157 // hack to allow the collection of the younger gen first if the flag is | |
1158 // set. This is better than using th policy's should_collect_gen0_first() | |
1159 // since that causes us to do an extra unnecessary pair of restart-&-stop-world. | |
1160 virtual bool full_collects_younger_generations() const { | |
1161 return UseCMSCompactAtFullCollection && !CollectGen0First; | |
1162 } | |
1163 | |
1164 void space_iterate(SpaceClosure* blk, bool usedOnly = false); | |
1165 | |
1166 // Support for compaction | |
1167 CompactibleSpace* first_compaction_space() const; | |
1168 // Adjust quantites in the generation affected by | |
1169 // the compaction. | |
1170 void reset_after_compaction(); | |
1171 | |
1172 // Allocation support | |
1173 HeapWord* allocate(size_t size, bool tlab); | |
1174 HeapWord* have_lock_and_allocate(size_t size, bool tlab); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
1175 oop promote(oop obj, size_t obj_size); |
0 | 1176 HeapWord* par_allocate(size_t size, bool tlab) { |
1177 return allocate(size, tlab); | |
1178 } | |
1179 | |
1180 // Incremental mode triggering. | |
1181 HeapWord* allocation_limit_reached(Space* space, HeapWord* top, | |
1182 size_t word_size); | |
1183 | |
1184 // Used by CMSStats to track direct allocation. The value is sampled and | |
1185 // reset after each young gen collection. | |
1186 size_t direct_allocated_words() const { return _direct_allocated_words; } | |
1187 void reset_direct_allocated_words() { _direct_allocated_words = 0; } | |
1188 | |
1189 // Overrides for parallel promotion. | |
1190 virtual oop par_promote(int thread_num, | |
1191 oop obj, markOop m, size_t word_sz); | |
1192 // This one should not be called for CMS. | |
1193 virtual void par_promote_alloc_undo(int thread_num, | |
1194 HeapWord* obj, size_t word_sz); | |
1195 virtual void par_promote_alloc_done(int thread_num); | |
1196 virtual void par_oop_since_save_marks_iterate_done(int thread_num); | |
1197 | |
1888
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1836
diff
changeset
|
1198 virtual bool promotion_attempt_is_safe(size_t promotion_in_bytes) const; |
0 | 1199 |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
935
diff
changeset
|
1200 // Inform this (non-young) generation that a promotion failure was |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
935
diff
changeset
|
1201 // encountered during a collection of a younger generation that |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
935
diff
changeset
|
1202 // promotes into this generation. |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
935
diff
changeset
|
1203 virtual void promotion_failure_occurred(); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
935
diff
changeset
|
1204 |
0 | 1205 bool should_collect(bool full, size_t size, bool tlab); |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
0
diff
changeset
|
1206 virtual bool should_concurrent_collect() const; |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
0
diff
changeset
|
1207 virtual bool is_too_full() const; |
0 | 1208 void collect(bool full, |
1209 bool clear_all_soft_refs, | |
1210 size_t size, | |
1211 bool tlab); | |
1212 | |
1213 HeapWord* expand_and_allocate(size_t word_size, | |
1214 bool tlab, | |
1215 bool parallel = false); | |
1216 | |
1217 // GC prologue and epilogue | |
1218 void gc_prologue(bool full); | |
1219 void gc_prologue_work(bool full, bool registerClosure, | |
1220 ModUnionClosure* modUnionClosure); | |
1221 void gc_epilogue(bool full); | |
1222 void gc_epilogue_work(bool full); | |
1223 | |
1224 // Time since last GC of this generation | |
1225 jlong time_of_last_gc(jlong now) { | |
1226 return collector()->time_of_last_gc(now); | |
1227 } | |
1228 void update_time_of_last_gc(jlong now) { | |
1229 collector()-> update_time_of_last_gc(now); | |
1230 } | |
1231 | |
1232 // Allocation failure | |
1233 void expand(size_t bytes, size_t expand_bytes, | |
1234 CMSExpansionCause::Cause cause); | |
271
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
196
diff
changeset
|
1235 virtual bool expand(size_t bytes, size_t expand_bytes); |
0 | 1236 void shrink(size_t bytes); |
9072
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8035
diff
changeset
|
1237 void shrink_by(size_t bytes); |
0 | 1238 HeapWord* expand_and_par_lab_allocate(CMSParGCThreadState* ps, size_t word_sz); |
1239 bool expand_and_ensure_spooling_space(PromotionInfo* promo); | |
1240 | |
1241 // Iteration support and related enquiries | |
1242 void save_marks(); | |
1243 bool no_allocs_since_save_marks(); | |
1244 void object_iterate_since_last_GC(ObjectClosure* cl); | |
1245 void younger_refs_iterate(OopsInGenClosure* cl); | |
1246 | |
1247 // Iteration support specific to CMS generations | |
1248 void save_sweep_limit(); | |
1249 | |
1250 // More iteration support | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1251 virtual void oop_iterate(MemRegion mr, ExtendedOopClosure* cl); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1252 virtual void oop_iterate(ExtendedOopClosure* cl); |
517
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
452
diff
changeset
|
1253 virtual void safe_object_iterate(ObjectClosure* cl); |
0 | 1254 virtual void object_iterate(ObjectClosure* cl); |
1255 | |
1256 // Need to declare the full complement of closures, whether we'll | |
1257 // override them or not, or get message from the compiler: | |
1258 // oop_since_save_marks_iterate_nv hides virtual function... | |
1259 #define CMS_SINCE_SAVE_MARKS_DECL(OopClosureType, nv_suffix) \ | |
1260 void oop_since_save_marks_iterate##nv_suffix(OopClosureType* cl); | |
1261 ALL_SINCE_SAVE_MARKS_CLOSURES(CMS_SINCE_SAVE_MARKS_DECL) | |
1262 | |
1263 // Smart allocation XXX -- move to CFLSpace? | |
1264 void setNearLargestChunk(); | |
1265 bool isNearLargestChunk(HeapWord* addr); | |
1266 | |
1267 // Get the chunk at the end of the space. Delagates to | |
1268 // the space. | |
1269 FreeChunk* find_chunk_at_end(); | |
1270 | |
1271 void post_compact(); | |
1272 | |
1273 // Debugging | |
1274 void prepare_for_verify(); | |
6008 | 1275 void verify(); |
0 | 1276 void print_statistics() PRODUCT_RETURN; |
1277 | |
1278 // Performance Counters support | |
1279 virtual void update_counters(); | |
1280 virtual void update_counters(size_t used); | |
1281 void initialize_performance_counters(); | |
1282 CollectorCounters* counters() { return collector()->counters(); } | |
1283 | |
1284 // Support for parallel remark of survivor space | |
1285 void* get_data_recorder(int thr_num) { | |
1286 //Delegate to collector | |
1287 return collector()->get_data_recorder(thr_num); | |
1288 } | |
1289 | |
1290 // Printing | |
1291 const char* name() const; | |
1292 virtual const char* short_name() const { return "CMS"; } | |
1293 void print() const; | |
1294 void printOccupancy(const char* s); | |
1295 bool must_be_youngest() const { return false; } | |
1296 bool must_be_oldest() const { return true; } | |
1297 | |
9072
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8035
diff
changeset
|
1298 // Resize the generation after a compacting GC. The |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8035
diff
changeset
|
1299 // generation can be treated as a contiguous space |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8035
diff
changeset
|
1300 // after the compaction. |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8035
diff
changeset
|
1301 virtual void compute_new_size(); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8035
diff
changeset
|
1302 // Resize the generation after a non-compacting |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8035
diff
changeset
|
1303 // collection. |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8035
diff
changeset
|
1304 void compute_new_size_free_list(); |
0 | 1305 |
1306 CollectionTypes debug_collection_type() { return _debug_collection_type; } | |
1307 void rotate_debug_collection_type(); | |
1308 }; | |
1309 | |
1310 class ASConcurrentMarkSweepGeneration : public ConcurrentMarkSweepGeneration { | |
1311 | |
1312 // Return the size policy from the heap's collector | |
1313 // policy casted to CMSAdaptiveSizePolicy*. | |
1314 CMSAdaptiveSizePolicy* cms_size_policy() const; | |
1315 | |
1316 // Resize the generation based on the adaptive size | |
1317 // policy. | |
1318 void resize(size_t cur_promo, size_t desired_promo); | |
1319 | |
1320 // Return the GC counters from the collector policy | |
1321 CMSGCAdaptivePolicyCounters* gc_adaptive_policy_counters(); | |
1322 | |
1323 virtual void shrink_by(size_t bytes); | |
1324 | |
1325 public: | |
1326 ASConcurrentMarkSweepGeneration(ReservedSpace rs, size_t initial_byte_size, | |
1327 int level, CardTableRS* ct, | |
1328 bool use_adaptive_freelists, | |
6026 | 1329 FreeBlockDictionary<FreeChunk>::DictionaryChoice |
0 | 1330 dictionaryChoice) : |
1331 ConcurrentMarkSweepGeneration(rs, initial_byte_size, level, ct, | |
1332 use_adaptive_freelists, dictionaryChoice) {} | |
1333 | |
1334 virtual const char* short_name() const { return "ASCMS"; } | |
1335 virtual Generation::Name kind() { return Generation::ASConcurrentMarkSweep; } | |
1336 | |
1337 virtual void update_counters(); | |
1338 virtual void update_counters(size_t used); | |
1339 }; | |
1340 | |
1341 // | |
1342 // Closures of various sorts used by CMS to accomplish its work | |
1343 // | |
1344 | |
1345 // This closure is used to check that a certain set of oops is empty. | |
1346 class FalseClosure: public OopClosure { | |
1347 public: | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
1348 void do_oop(oop* p) { guarantee(false, "Should be an empty set"); } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
1349 void do_oop(narrowOop* p) { guarantee(false, "Should be an empty set"); } |
0 | 1350 }; |
1351 | |
1352 // This closure is used to do concurrent marking from the roots | |
1353 // following the first checkpoint. | |
1354 class MarkFromRootsClosure: public BitMapClosure { | |
1355 CMSCollector* _collector; | |
1356 MemRegion _span; | |
1357 CMSBitMap* _bitMap; | |
1358 CMSBitMap* _mut; | |
1359 CMSMarkStack* _markStack; | |
1360 bool _yield; | |
1361 int _skipBits; | |
1362 HeapWord* _finger; | |
1363 HeapWord* _threshold; | |
1364 DEBUG_ONLY(bool _verifying;) | |
1365 | |
1366 public: | |
1367 MarkFromRootsClosure(CMSCollector* collector, MemRegion span, | |
1368 CMSBitMap* bitMap, | |
1369 CMSMarkStack* markStack, | |
1370 bool should_yield, bool verifying = false); | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
1371 bool do_bit(size_t offset); |
0 | 1372 void reset(HeapWord* addr); |
1373 inline void do_yield_check(); | |
1374 | |
1375 private: | |
1376 void scanOopsInOop(HeapWord* ptr); | |
1377 void do_yield_work(); | |
1378 }; | |
1379 | |
1380 // This closure is used to do concurrent multi-threaded | |
1381 // marking from the roots following the first checkpoint. | |
1382 // XXX This should really be a subclass of The serial version | |
1383 // above, but i have not had the time to refactor things cleanly. | |
1384 // That willbe done for Dolphin. | |
1385 class Par_MarkFromRootsClosure: public BitMapClosure { | |
1386 CMSCollector* _collector; | |
1387 MemRegion _whole_span; | |
1388 MemRegion _span; | |
1389 CMSBitMap* _bit_map; | |
1390 CMSBitMap* _mut; | |
1391 OopTaskQueue* _work_queue; | |
1392 CMSMarkStack* _overflow_stack; | |
1393 bool _yield; | |
1394 int _skip_bits; | |
1395 HeapWord* _finger; | |
1396 HeapWord* _threshold; | |
1397 CMSConcMarkingTask* _task; | |
1398 public: | |
1399 Par_MarkFromRootsClosure(CMSConcMarkingTask* task, CMSCollector* collector, | |
1400 MemRegion span, | |
1401 CMSBitMap* bit_map, | |
1402 OopTaskQueue* work_queue, | |
1403 CMSMarkStack* overflow_stack, | |
1404 bool should_yield); | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
1405 bool do_bit(size_t offset); |
0 | 1406 inline void do_yield_check(); |
1407 | |
1408 private: | |
1409 void scan_oops_in_oop(HeapWord* ptr); | |
1410 void do_yield_work(); | |
1411 bool get_work_from_overflow_stack(); | |
1412 }; | |
1413 | |
1414 // The following closures are used to do certain kinds of verification of | |
1415 // CMS marking. | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1416 class PushAndMarkVerifyClosure: public CMSOopClosure { |
0 | 1417 CMSCollector* _collector; |
1418 MemRegion _span; | |
1419 CMSBitMap* _verification_bm; | |
1420 CMSBitMap* _cms_bm; | |
1421 CMSMarkStack* _mark_stack; | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
1422 protected: |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
1423 void do_oop(oop p); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
1424 template <class T> inline void do_oop_work(T *p) { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1425 oop obj = oopDesc::load_decode_heap_oop(p); |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
1426 do_oop(obj); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
1427 } |
0 | 1428 public: |
1429 PushAndMarkVerifyClosure(CMSCollector* cms_collector, | |
1430 MemRegion span, | |
1431 CMSBitMap* verification_bm, | |
1432 CMSBitMap* cms_bm, | |
1433 CMSMarkStack* mark_stack); | |
1434 void do_oop(oop* p); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
1435 void do_oop(narrowOop* p); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1436 |
0 | 1437 // Deal with a stack overflow condition |
1438 void handle_stack_overflow(HeapWord* lost); | |
1439 }; | |
1440 | |
1441 class MarkFromRootsVerifyClosure: public BitMapClosure { | |
1442 CMSCollector* _collector; | |
1443 MemRegion _span; | |
1444 CMSBitMap* _verification_bm; | |
1445 CMSBitMap* _cms_bm; | |
1446 CMSMarkStack* _mark_stack; | |
1447 HeapWord* _finger; | |
1448 PushAndMarkVerifyClosure _pam_verify_closure; | |
1449 public: | |
1450 MarkFromRootsVerifyClosure(CMSCollector* collector, MemRegion span, | |
1451 CMSBitMap* verification_bm, | |
1452 CMSBitMap* cms_bm, | |
1453 CMSMarkStack* mark_stack); | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
1454 bool do_bit(size_t offset); |
0 | 1455 void reset(HeapWord* addr); |
1456 }; | |
1457 | |
1458 | |
1459 // This closure is used to check that a certain set of bits is | |
1460 // "empty" (i.e. the bit vector doesn't have any 1-bits). | |
1461 class FalseBitMapClosure: public BitMapClosure { | |
1462 public: | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
1463 bool do_bit(size_t offset) { |
0 | 1464 guarantee(false, "Should not have a 1 bit"); |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
1465 return true; |
0 | 1466 } |
1467 }; | |
1468 | |
1469 // This closure is used during the second checkpointing phase | |
1470 // to rescan the marked objects on the dirty cards in the mod | |
1471 // union table and the card table proper. It's invoked via | |
1472 // MarkFromDirtyCardsClosure below. It uses either | |
1473 // [Par_]MarkRefsIntoAndScanClosure (Par_ in the parallel case) | |
1474 // declared in genOopClosures.hpp to accomplish some of its work. | |
1475 // In the parallel case the bitMap is shared, so access to | |
1476 // it needs to be suitably synchronized for updates by embedded | |
1477 // closures that update it; however, this closure itself only | |
1478 // reads the bit_map and because it is idempotent, is immune to | |
1479 // reading stale values. | |
1480 class ScanMarkedObjectsAgainClosure: public UpwardsObjectClosure { | |
1481 #ifdef ASSERT | |
1482 CMSCollector* _collector; | |
1483 MemRegion _span; | |
1484 union { | |
1485 CMSMarkStack* _mark_stack; | |
1486 OopTaskQueue* _work_queue; | |
1487 }; | |
1488 #endif // ASSERT | |
1489 bool _parallel; | |
1490 CMSBitMap* _bit_map; | |
1491 union { | |
1492 MarkRefsIntoAndScanClosure* _scan_closure; | |
1493 Par_MarkRefsIntoAndScanClosure* _par_scan_closure; | |
1494 }; | |
1495 | |
1496 public: | |
1497 ScanMarkedObjectsAgainClosure(CMSCollector* collector, | |
1498 MemRegion span, | |
1499 ReferenceProcessor* rp, | |
1500 CMSBitMap* bit_map, | |
1501 CMSMarkStack* mark_stack, | |
1502 MarkRefsIntoAndScanClosure* cl): | |
1503 #ifdef ASSERT | |
1504 _collector(collector), | |
1505 _span(span), | |
1506 _mark_stack(mark_stack), | |
1507 #endif // ASSERT | |
1508 _parallel(false), | |
1509 _bit_map(bit_map), | |
1510 _scan_closure(cl) { } | |
1511 | |
1512 ScanMarkedObjectsAgainClosure(CMSCollector* collector, | |
1513 MemRegion span, | |
1514 ReferenceProcessor* rp, | |
1515 CMSBitMap* bit_map, | |
1516 OopTaskQueue* work_queue, | |
1517 Par_MarkRefsIntoAndScanClosure* cl): | |
1518 #ifdef ASSERT | |
1519 _collector(collector), | |
1520 _span(span), | |
1521 _work_queue(work_queue), | |
1522 #endif // ASSERT | |
1523 _parallel(true), | |
1524 _bit_map(bit_map), | |
1525 _par_scan_closure(cl) { } | |
1526 | |
1527 void do_object(oop obj) { | |
1528 guarantee(false, "Call do_object_b(oop, MemRegion) instead"); | |
1529 } | |
1530 bool do_object_b(oop obj) { | |
1531 guarantee(false, "Call do_object_b(oop, MemRegion) form instead"); | |
1532 return false; | |
1533 } | |
1534 bool do_object_bm(oop p, MemRegion mr); | |
1535 }; | |
1536 | |
1537 // This closure is used during the second checkpointing phase | |
1538 // to rescan the marked objects on the dirty cards in the mod | |
1539 // union table and the card table proper. It invokes | |
1540 // ScanMarkedObjectsAgainClosure above to accomplish much of its work. | |
1541 // In the parallel case, the bit map is shared and requires | |
1542 // synchronized access. | |
1543 class MarkFromDirtyCardsClosure: public MemRegionClosure { | |
1544 CompactibleFreeListSpace* _space; | |
1545 ScanMarkedObjectsAgainClosure _scan_cl; | |
1546 size_t _num_dirty_cards; | |
1547 | |
1548 public: | |
1549 MarkFromDirtyCardsClosure(CMSCollector* collector, | |
1550 MemRegion span, | |
1551 CompactibleFreeListSpace* space, | |
1552 CMSBitMap* bit_map, | |
1553 CMSMarkStack* mark_stack, | |
1554 MarkRefsIntoAndScanClosure* cl): | |
1555 _space(space), | |
1556 _num_dirty_cards(0), | |
1557 _scan_cl(collector, span, collector->ref_processor(), bit_map, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1558 mark_stack, cl) { } |
0 | 1559 |
1560 MarkFromDirtyCardsClosure(CMSCollector* collector, | |
1561 MemRegion span, | |
1562 CompactibleFreeListSpace* space, | |
1563 CMSBitMap* bit_map, | |
1564 OopTaskQueue* work_queue, | |
1565 Par_MarkRefsIntoAndScanClosure* cl): | |
1566 _space(space), | |
1567 _num_dirty_cards(0), | |
1568 _scan_cl(collector, span, collector->ref_processor(), bit_map, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1569 work_queue, cl) { } |
0 | 1570 |
1571 void do_MemRegion(MemRegion mr); | |
1572 void set_space(CompactibleFreeListSpace* space) { _space = space; } | |
1573 size_t num_dirty_cards() { return _num_dirty_cards; } | |
1574 }; | |
1575 | |
1576 // This closure is used in the non-product build to check | |
1577 // that there are no MemRegions with a certain property. | |
1578 class FalseMemRegionClosure: public MemRegionClosure { | |
1579 void do_MemRegion(MemRegion mr) { | |
1580 guarantee(!mr.is_empty(), "Shouldn't be empty"); | |
1581 guarantee(false, "Should never be here"); | |
1582 } | |
1583 }; | |
1584 | |
1585 // This closure is used during the precleaning phase | |
1586 // to "carefully" rescan marked objects on dirty cards. | |
1587 // It uses MarkRefsIntoAndScanClosure declared in genOopClosures.hpp | |
1588 // to accomplish some of its work. | |
1589 class ScanMarkedObjectsAgainCarefullyClosure: public ObjectClosureCareful { | |
1590 CMSCollector* _collector; | |
1591 MemRegion _span; | |
1592 bool _yield; | |
1593 Mutex* _freelistLock; | |
1594 CMSBitMap* _bitMap; | |
1595 CMSMarkStack* _markStack; | |
1596 MarkRefsIntoAndScanClosure* _scanningClosure; | |
1597 | |
1598 public: | |
1599 ScanMarkedObjectsAgainCarefullyClosure(CMSCollector* collector, | |
1600 MemRegion span, | |
1601 CMSBitMap* bitMap, | |
1602 CMSMarkStack* markStack, | |
1603 MarkRefsIntoAndScanClosure* cl, | |
1604 bool should_yield): | |
1605 _collector(collector), | |
1606 _span(span), | |
1607 _yield(should_yield), | |
1608 _bitMap(bitMap), | |
1609 _markStack(markStack), | |
1610 _scanningClosure(cl) { | |
1611 } | |
1612 | |
1613 void do_object(oop p) { | |
1614 guarantee(false, "call do_object_careful instead"); | |
1615 } | |
1616 | |
1617 size_t do_object_careful(oop p) { | |
1618 guarantee(false, "Unexpected caller"); | |
1619 return 0; | |
1620 } | |
1621 | |
1622 size_t do_object_careful_m(oop p, MemRegion mr); | |
1623 | |
1624 void setFreelistLock(Mutex* m) { | |
1625 _freelistLock = m; | |
1626 _scanningClosure->set_freelistLock(m); | |
1627 } | |
1628 | |
1629 private: | |
1630 inline bool do_yield_check(); | |
1631 | |
1632 void do_yield_work(); | |
1633 }; | |
1634 | |
1635 class SurvivorSpacePrecleanClosure: public ObjectClosureCareful { | |
1636 CMSCollector* _collector; | |
1637 MemRegion _span; | |
1638 bool _yield; | |
1639 CMSBitMap* _bit_map; | |
1640 CMSMarkStack* _mark_stack; | |
1641 PushAndMarkClosure* _scanning_closure; | |
1642 unsigned int _before_count; | |
1643 | |
1644 public: | |
1645 SurvivorSpacePrecleanClosure(CMSCollector* collector, | |
1646 MemRegion span, | |
1647 CMSBitMap* bit_map, | |
1648 CMSMarkStack* mark_stack, | |
1649 PushAndMarkClosure* cl, | |
1650 unsigned int before_count, | |
1651 bool should_yield): | |
1652 _collector(collector), | |
1653 _span(span), | |
1654 _yield(should_yield), | |
1655 _bit_map(bit_map), | |
1656 _mark_stack(mark_stack), | |
1657 _scanning_closure(cl), | |
1658 _before_count(before_count) | |
1659 { } | |
1660 | |
1661 void do_object(oop p) { | |
1662 guarantee(false, "call do_object_careful instead"); | |
1663 } | |
1664 | |
1665 size_t do_object_careful(oop p); | |
1666 | |
1667 size_t do_object_careful_m(oop p, MemRegion mr) { | |
1668 guarantee(false, "Unexpected caller"); | |
1669 return 0; | |
1670 } | |
1671 | |
1672 private: | |
1673 inline void do_yield_check(); | |
1674 void do_yield_work(); | |
1675 }; | |
1676 | |
1677 // This closure is used to accomplish the sweeping work | |
1678 // after the second checkpoint but before the concurrent reset | |
1679 // phase. | |
1680 // | |
1681 // Terminology | |
1682 // left hand chunk (LHC) - block of one or more chunks currently being | |
1683 // coalesced. The LHC is available for coalescing with a new chunk. | |
1684 // right hand chunk (RHC) - block that is currently being swept that is | |
1685 // free or garbage that can be coalesced with the LHC. | |
1686 // _inFreeRange is true if there is currently a LHC | |
1687 // _lastFreeRangeCoalesced is true if the LHC consists of more than one chunk. | |
1688 // _freeRangeInFreeLists is true if the LHC is in the free lists. | |
1689 // _freeFinger is the address of the current LHC | |
1690 class SweepClosure: public BlkClosureCareful { | |
1691 CMSCollector* _collector; // collector doing the work | |
1692 ConcurrentMarkSweepGeneration* _g; // Generation being swept | |
1693 CompactibleFreeListSpace* _sp; // Space being swept | |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
1694 HeapWord* _limit;// the address at or above which the sweep should stop |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
1695 // because we do not expect newly garbage blocks |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
1696 // eligible for sweeping past that address. |
0 | 1697 Mutex* _freelistLock; // Free list lock (in space) |
1698 CMSBitMap* _bitMap; // Marking bit map (in | |
1699 // generation) | |
1700 bool _inFreeRange; // Indicates if we are in the | |
1701 // midst of a free run | |
1702 bool _freeRangeInFreeLists; | |
1703 // Often, we have just found | |
1704 // a free chunk and started | |
1705 // a new free range; we do not | |
1706 // eagerly remove this chunk from | |
1707 // the free lists unless there is | |
1708 // a possibility of coalescing. | |
1709 // When true, this flag indicates | |
1710 // that the _freeFinger below | |
1711 // points to a potentially free chunk | |
1712 // that may still be in the free lists | |
1713 bool _lastFreeRangeCoalesced; | |
1714 // free range contains chunks | |
1715 // coalesced | |
1716 bool _yield; | |
1717 // Whether sweeping should be | |
1718 // done with yields. For instance | |
1719 // when done by the foreground | |
1720 // collector we shouldn't yield. | |
1721 HeapWord* _freeFinger; // When _inFreeRange is set, the | |
1722 // pointer to the "left hand | |
1723 // chunk" | |
1724 size_t _freeRangeSize; | |
1725 // When _inFreeRange is set, this | |
1726 // indicates the accumulated size | |
1727 // of the "left hand chunk" | |
1728 NOT_PRODUCT( | |
1729 size_t _numObjectsFreed; | |
1730 size_t _numWordsFreed; | |
1731 size_t _numObjectsLive; | |
1732 size_t _numWordsLive; | |
1733 size_t _numObjectsAlreadyFree; | |
1734 size_t _numWordsAlreadyFree; | |
1735 FreeChunk* _last_fc; | |
1736 ) | |
1737 private: | |
1738 // Code that is common to a free chunk or garbage when | |
1739 // encountered during sweeping. | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1972
diff
changeset
|
1740 void do_post_free_or_garbage_chunk(FreeChunk *fc, size_t chunkSize); |
0 | 1741 // Process a free chunk during sweeping. |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1972
diff
changeset
|
1742 void do_already_free_chunk(FreeChunk *fc); |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
1743 // Work method called when processing an already free or a |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
1744 // freshly garbage chunk to do a lookahead and possibly a |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
1745 // premptive flush if crossing over _limit. |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
1746 void lookahead_and_flush(FreeChunk* fc, size_t chunkSize); |
0 | 1747 // Process a garbage chunk during sweeping. |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1972
diff
changeset
|
1748 size_t do_garbage_chunk(FreeChunk *fc); |
0 | 1749 // Process a live chunk during sweeping. |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1972
diff
changeset
|
1750 size_t do_live_chunk(FreeChunk* fc); |
0 | 1751 |
1752 // Accessors. | |
1753 HeapWord* freeFinger() const { return _freeFinger; } | |
1754 void set_freeFinger(HeapWord* v) { _freeFinger = v; } | |
1755 bool inFreeRange() const { return _inFreeRange; } | |
1756 void set_inFreeRange(bool v) { _inFreeRange = v; } | |
1757 bool lastFreeRangeCoalesced() const { return _lastFreeRangeCoalesced; } | |
1758 void set_lastFreeRangeCoalesced(bool v) { _lastFreeRangeCoalesced = v; } | |
1759 bool freeRangeInFreeLists() const { return _freeRangeInFreeLists; } | |
1760 void set_freeRangeInFreeLists(bool v) { _freeRangeInFreeLists = v; } | |
1761 | |
1762 // Initialize a free range. | |
1763 void initialize_free_range(HeapWord* freeFinger, bool freeRangeInFreeLists); | |
1764 // Return this chunk to the free lists. | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1972
diff
changeset
|
1765 void flush_cur_free_chunk(HeapWord* chunk, size_t size); |
0 | 1766 |
1767 // Check if we should yield and do so when necessary. | |
1768 inline void do_yield_check(HeapWord* addr); | |
1769 | |
1770 // Yield | |
1771 void do_yield_work(HeapWord* addr); | |
1772 | |
1773 // Debugging/Printing | |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
1774 void print_free_block_coalesced(FreeChunk* fc) const; |
0 | 1775 |
1776 public: | |
1777 SweepClosure(CMSCollector* collector, ConcurrentMarkSweepGeneration* g, | |
1778 CMSBitMap* bitMap, bool should_yield); | |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
1779 ~SweepClosure() PRODUCT_RETURN; |
0 | 1780 |
1781 size_t do_blk_careful(HeapWord* addr); | |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
1782 void print() const { print_on(tty); } |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
1783 void print_on(outputStream *st) const; |
0 | 1784 }; |
1785 | |
1786 // Closures related to weak references processing | |
1787 | |
1788 // During CMS' weak reference processing, this is a | |
1789 // work-routine/closure used to complete transitive | |
1790 // marking of objects as live after a certain point | |
1791 // in which an initial set has been completely accumulated. | |
452
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
356
diff
changeset
|
1792 // This closure is currently used both during the final |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
356
diff
changeset
|
1793 // remark stop-world phase, as well as during the concurrent |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
356
diff
changeset
|
1794 // precleaning of the discovered reference lists. |
0 | 1795 class CMSDrainMarkingStackClosure: public VoidClosure { |
1796 CMSCollector* _collector; | |
1797 MemRegion _span; | |
1798 CMSMarkStack* _mark_stack; | |
1799 CMSBitMap* _bit_map; | |
1800 CMSKeepAliveClosure* _keep_alive; | |
452
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
356
diff
changeset
|
1801 bool _concurrent_precleaning; |
0 | 1802 public: |
1803 CMSDrainMarkingStackClosure(CMSCollector* collector, MemRegion span, | |
1804 CMSBitMap* bit_map, CMSMarkStack* mark_stack, | |
452
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
356
diff
changeset
|
1805 CMSKeepAliveClosure* keep_alive, |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
356
diff
changeset
|
1806 bool cpc): |
0 | 1807 _collector(collector), |
1808 _span(span), | |
1809 _bit_map(bit_map), | |
1810 _mark_stack(mark_stack), | |
452
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
356
diff
changeset
|
1811 _keep_alive(keep_alive), |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
356
diff
changeset
|
1812 _concurrent_precleaning(cpc) { |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
356
diff
changeset
|
1813 assert(_concurrent_precleaning == _keep_alive->concurrent_precleaning(), |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
356
diff
changeset
|
1814 "Mismatch"); |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
356
diff
changeset
|
1815 } |
0 | 1816 |
1817 void do_void(); | |
1818 }; | |
1819 | |
1820 // A parallel version of CMSDrainMarkingStackClosure above. | |
1821 class CMSParDrainMarkingStackClosure: public VoidClosure { | |
1822 CMSCollector* _collector; | |
1823 MemRegion _span; | |
1824 OopTaskQueue* _work_queue; | |
1825 CMSBitMap* _bit_map; | |
1826 CMSInnerParMarkAndPushClosure _mark_and_push; | |
1827 | |
1828 public: | |
1829 CMSParDrainMarkingStackClosure(CMSCollector* collector, | |
1830 MemRegion span, CMSBitMap* bit_map, | |
1831 OopTaskQueue* work_queue): | |
1832 _collector(collector), | |
1833 _span(span), | |
1834 _bit_map(bit_map), | |
1835 _work_queue(work_queue), | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1836 _mark_and_push(collector, span, bit_map, work_queue) { } |
0 | 1837 |
1838 public: | |
1839 void trim_queue(uint max); | |
1840 void do_void(); | |
1841 }; | |
1842 | |
1843 // Allow yielding or short-circuiting of reference list | |
1844 // prelceaning work. | |
1845 class CMSPrecleanRefsYieldClosure: public YieldClosure { | |
1846 CMSCollector* _collector; | |
1847 void do_yield_work(); | |
1848 public: | |
1849 CMSPrecleanRefsYieldClosure(CMSCollector* collector): | |
1850 _collector(collector) {} | |
1851 virtual bool should_return(); | |
1852 }; | |
1853 | |
1854 | |
1855 // Convenience class that locks free list locks for given CMS collector | |
1856 class FreelistLocker: public StackObj { | |
1857 private: | |
1858 CMSCollector* _collector; | |
1859 public: | |
1860 FreelistLocker(CMSCollector* collector): | |
1861 _collector(collector) { | |
1862 _collector->getFreelistLocks(); | |
1863 } | |
1864 | |
1865 ~FreelistLocker() { | |
1866 _collector->releaseFreelistLocks(); | |
1867 } | |
1868 }; | |
1869 | |
1870 // Mark all dead objects in a given space. | |
1871 class MarkDeadObjectsClosure: public BlkClosure { | |
1872 const CMSCollector* _collector; | |
1873 const CompactibleFreeListSpace* _sp; | |
1874 CMSBitMap* _live_bit_map; | |
1875 CMSBitMap* _dead_bit_map; | |
1876 public: | |
1877 MarkDeadObjectsClosure(const CMSCollector* collector, | |
1878 const CompactibleFreeListSpace* sp, | |
1879 CMSBitMap *live_bit_map, | |
1880 CMSBitMap *dead_bit_map) : | |
1881 _collector(collector), | |
1882 _sp(sp), | |
1883 _live_bit_map(live_bit_map), | |
1884 _dead_bit_map(dead_bit_map) {} | |
1885 size_t do_blk(HeapWord* addr); | |
1886 }; | |
1703
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1552
diff
changeset
|
1887 |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1552
diff
changeset
|
1888 class TraceCMSMemoryManagerStats : public TraceMemoryManagerStats { |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1552
diff
changeset
|
1889 |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1552
diff
changeset
|
1890 public: |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2369
diff
changeset
|
1891 TraceCMSMemoryManagerStats(CMSCollector::CollectorState phase, GCCause::Cause cause); |
1703
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1552
diff
changeset
|
1892 }; |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1552
diff
changeset
|
1893 |
1972 | 1894 |
1895 #endif // SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_CONCURRENTMARKSWEEPGENERATION_HPP |