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