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