27 #include "gc/shared/cmBitMap.hpp"
28
29 class ConcurrentGCTimer;
30
31 class ShenandoahCollectorPolicy;
32 class ShenandoahHeapRegion;
33 class ShenandoahHeapRegionClosure;
34 class ShenandoahHeapRegionSet;
35 class ShenandoahCollectionSet;
36 class ShenandoahFreeSet;
37 class ShenandoahConcurrentMark;
38 class ShenandoahConcurrentThread;
39 class ShenandoahMonitoringSupport;
40
41 class ShenandoahAlwaysTrueClosure : public BoolObjectClosure {
42 public:
43 bool do_object_b(oop p) { return true; }
44 };
45
46
47 class ShenandoahIsAliveClosure: public BoolObjectClosure {
48 private:
49 ShenandoahHeap* _heap;
50 public:
51 ShenandoahIsAliveClosure();
52 void init(ShenandoahHeap* heap);
53 bool do_object_b(oop obj);
54 };
55
56 class ShenandoahForwardedIsAliveClosure: public BoolObjectClosure {
57 private:
58 ShenandoahHeap* _heap;
59 public:
60 ShenandoahForwardedIsAliveClosure();
61 void init(ShenandoahHeap* heap);
62 bool do_object_b(oop obj);
63 };
64
65
66 // // A "ShenandoahHeap" is an implementation of a java heap for HotSpot.
67 // // It uses a new pauseless GC algorithm based on Brooks pointers.
68 // // Derived from G1
69
70 // //
71 // // CollectedHeap
72 // // SharedHeap
73 // // ShenandoahHeap
74
75 class ShenandoahHeap : public CollectedHeap {
97 ShenandoahMonitoringSupport* _monitoring_support;
98
99 size_t _num_regions;
100 size_t _max_regions;
101 size_t _initialSize;
102 #ifndef NDEBUG
103 uint _numAllocs;
104 #endif
105 uint _max_parallel_workers;
106 uint _max_conc_workers;
107 uint _max_workers;
108
109 WorkGang* _conc_workers;
110 WorkGang* _workers;
111
112
113 volatile size_t _used;
114
115 CMBitMap _mark_bit_map0;
116 CMBitMap _mark_bit_map1;
117 CMBitMap* _prev_mark_bit_map;
118 CMBitMap* _next_mark_bit_map;
119
120 bool* _in_cset_fast_test;
121 bool* _in_cset_fast_test_base;
122 size_t _in_cset_fast_test_length;
123
124 HeapWord** _top_at_mark_starts;
125 HeapWord** _top_at_mark_starts_base;
126
127 volatile jbyte _cancelled_concgc;
128
129 jbyte _growing_heap;
130
131 size_t _bytes_allocated_since_cm;
132 size_t _bytes_allocated_during_cm;
133 size_t _bytes_allocated_during_cm_start;
134 size_t _max_allocated_gc;
135 size_t _allocated_last_gc;
136 size_t _used_start_gc;
137
138 unsigned int _concurrent_mark_in_progress;
139
140 bool _full_gc_in_progress;
141
142 unsigned int _evacuation_in_progress;
143 bool _need_update_refs;
144 bool _need_reset_bitmaps;
145
230 inline oop maybe_update_oop_ref(T* p);
231
232 void recycle_dirty_regions();
233
234 void start_concurrent_marking();
235 void stop_concurrent_marking();
236 inline bool concurrent_mark_in_progress();
237 static address concurrent_mark_in_progress_addr();
238
239 void prepare_for_concurrent_evacuation();
240 void evacuate_and_update_roots();
241 inline bool is_evacuation_in_progress();
242 void set_evacuation_in_progress(bool in_progress);
243
244 void set_full_gc_in_progress(bool in_progress);
245 bool is_full_gc_in_progress() const;
246
247 inline bool need_update_refs() const;
248 void set_need_update_refs(bool update_refs);
249
250 inline bool in_cset_fast_test(HeapWord* obj);
251 void clear_cset_fast_test();
252 void register_region_with_in_cset_fast_test(ShenandoahHeapRegion* r);
253
254 inline bool allocated_after_mark_start(HeapWord* addr) const;
255 void set_top_at_mark_start(HeapWord* region_base, HeapWord* addr);
256
257 inline oop evacuate_object(oop src, Thread* thread);
258 inline bool cancelled_concgc() const;
259 void clear_cancelled_concgc();
260
261 ShenandoahHeapRegionSet* regions() { return _ordered_regions;}
262 ShenandoahHeapRegionSet* sorted_regions() { return _sorted_regions;}
263 ShenandoahFreeSet* free_regions();
264 void clear_free_regions();
265 void add_free_region(ShenandoahHeapRegion* r);
266
267 void increase_used(size_t bytes);
268 void decrease_used(size_t bytes);
269
270 void set_used(size_t bytes);
271 size_t calculateUsed();
272
273 void reset_mark_bitmap(WorkGang* gang);
274 void reset_prev_mark_bitmap(WorkGang* gang);
275 void reset_mark_bitmap_range(HeapWord* from, HeapWord* to);
276 void reset_prev_mark_bitmap_range(HeapWord* from, HeapWord* to);
277 CMBitMap* prev_mark_bit_map();
278 CMBitMap* next_mark_bit_map();
279 inline bool is_marked_prev(oop obj) const;
280 inline bool mark_current(oop obj) const;
281 inline bool is_marked_current(oop obj) const;
282 bool is_obj_dead(const oop obj, const ShenandoahHeapRegion* r) const;
283 bool is_bitmap_clear();
284
285 void parallel_evacuate_region(ShenandoahHeapRegion* from_region);
286
287 template <class T>
288 inline oop update_oop_ref_not_null(T* p, oop obj);
289
290 void print_heap_regions(outputStream* st = tty) const;
291 void print_all_refs(const char* prefix);
292 void print_heap_locations(HeapWord* start, HeapWord* end);
293
294 size_t bytes_allocated_since_cm();
295 void set_bytes_allocated_since_cm(size_t bytes);
296
297 size_t max_allocated_gc();
298
299 void reclaim_humongous_region_at(ShenandoahHeapRegion* r);
300
301 VirtualSpace* storage() const;
302
303 ShenandoahMonitoringSupport* monitoring_support();
312 uint max_workers();
313 uint max_parallel_workers();
314
315 void do_evacuation();
316 ShenandoahHeapRegion* next_compaction_region(const ShenandoahHeapRegion* r);
317
318 void heap_region_iterate(ShenandoahHeapRegionClosure* blk, bool skip_dirty_regions = false, bool skip_humongous_continuation = false) const;
319
320 void verify_heap_after_evacuation();
321
322 // Delete entries for dead interned string and clean up unreferenced symbols
323 // in symbol table, possibly in parallel.
324 void unlink_string_and_symbol_table(BoolObjectClosure* is_alive, bool unlink_strings = true, bool unlink_symbols = true);
325
326 size_t num_regions();
327 size_t max_regions();
328
329 // TODO: consider moving this into ShenandoahHeapRegion.
330
331 template<class T>
332 inline void marked_prev_object_iterate(ShenandoahHeapRegion* region, T* cl);
333
334 template<class T>
335 inline void marked_next_object_iterate(ShenandoahHeapRegion* region, T* cl);
336
337 GCTimer* gc_timer() const;
338
339 private:
340 HeapWord* allocate_new_tlab(size_t word_size, bool mark);
341 HeapWord* allocate_memory(size_t word_size, bool evacuating);
342 // Shenandoah functionality.
343 inline HeapWord* allocate_from_gclab(Thread* thread, size_t size);
344 HeapWord* allocate_from_gclab_slow(Thread* thread, size_t size);
345 HeapWord* allocate_new_gclab(size_t word_size);
346
347 void roots_iterate(OopClosure* cl);
348
349 template<class T>
350 inline void marked_object_iterate(ShenandoahHeapRegion* region, T* cl, CMBitMap* mark_bit_map, HeapWord* top_at_mark_start);
351
352 template<class T>
353 inline void do_marked_object(CMBitMap* bitmap, T* cl, oop obj);
354
355 ShenandoahConcurrentThread* concurrent_thread() { return _concurrent_gc_thread; }
356
357 void swap_mark_bitmaps();
358
359 inline bool mark_current_no_checks(oop obj) const;
360 inline bool is_marked_current(oop obj, ShenandoahHeapRegion* r) const;
361
362 inline bool is_marked_prev(oop obj, const ShenandoahHeapRegion* r) const;
363
364 void parallel_evacuate();
365
366 template <class T>
367 inline oop maybe_update_oop_ref_not_null(T* p, oop obj);
368
369 inline oop atomic_compare_exchange_oop(oop n, narrowOop* addr, oop c);
370 inline oop atomic_compare_exchange_oop(oop n, oop* addr, oop c);
371
372 void evacuate_region(ShenandoahHeapRegion* from_region, ShenandoahHeapRegion* to_region);
373
374 #ifdef ASSERT
375 void verify_evacuated_region(ShenandoahHeapRegion* from_region);
376 #endif
377
378 bool is_in_collection_set(const void* p);
379
380 inline void copy_object(oop p, HeapWord* s, size_t words);
381 void verify_copy(oop p, oop c);
382 void verify_heap_size_consistency();
383 void verify_heap_after_marking();
384 void verify_heap_after_update_refs();
385 void verify_regions_after_update_refs();
386
387 void ref_processing_init();
388
389 GCTracer* tracer();
390 ShenandoahCollectionSet* collection_set() { return _collection_set; }
391
392 bool call_from_write_barrier(bool evacuating);
393 bool check_grow_heap();
394 void grow_heap_by(size_t num_regions);
395 void ensure_new_regions(size_t num_new_regions);
396
397 void verify_evacuation(ShenandoahHeapRegion* from_region);
398 void set_concurrent_mark_in_progress(bool in_progress);
|
27 #include "gc/shared/cmBitMap.hpp"
28
29 class ConcurrentGCTimer;
30
31 class ShenandoahCollectorPolicy;
32 class ShenandoahHeapRegion;
33 class ShenandoahHeapRegionClosure;
34 class ShenandoahHeapRegionSet;
35 class ShenandoahCollectionSet;
36 class ShenandoahFreeSet;
37 class ShenandoahConcurrentMark;
38 class ShenandoahConcurrentThread;
39 class ShenandoahMonitoringSupport;
40
41 class ShenandoahAlwaysTrueClosure : public BoolObjectClosure {
42 public:
43 bool do_object_b(oop p) { return true; }
44 };
45
46
47 class ShenandoahForwardedIsAliveClosure: public BoolObjectClosure {
48 private:
49 ShenandoahHeap* _heap;
50 public:
51 ShenandoahForwardedIsAliveClosure();
52 void init(ShenandoahHeap* heap);
53 bool do_object_b(oop obj);
54 };
55
56
57 // // A "ShenandoahHeap" is an implementation of a java heap for HotSpot.
58 // // It uses a new pauseless GC algorithm based on Brooks pointers.
59 // // Derived from G1
60
61 // //
62 // // CollectedHeap
63 // // SharedHeap
64 // // ShenandoahHeap
65
66 class ShenandoahHeap : public CollectedHeap {
88 ShenandoahMonitoringSupport* _monitoring_support;
89
90 size_t _num_regions;
91 size_t _max_regions;
92 size_t _initialSize;
93 #ifndef NDEBUG
94 uint _numAllocs;
95 #endif
96 uint _max_parallel_workers;
97 uint _max_conc_workers;
98 uint _max_workers;
99
100 WorkGang* _conc_workers;
101 WorkGang* _workers;
102
103
104 volatile size_t _used;
105
106 CMBitMap _mark_bit_map0;
107 CMBitMap _mark_bit_map1;
108 CMBitMap* _complete_mark_bit_map;
109 CMBitMap* _next_mark_bit_map;
110
111 bool* _in_cset_fast_test;
112 bool* _in_cset_fast_test_base;
113 size_t _in_cset_fast_test_length;
114
115 HeapWord** _complete_top_at_mark_starts;
116 HeapWord** _complete_top_at_mark_starts_base;
117
118 HeapWord** _next_top_at_mark_starts;
119 HeapWord** _next_top_at_mark_starts_base;
120
121 volatile jbyte _cancelled_concgc;
122
123 jbyte _growing_heap;
124
125 size_t _bytes_allocated_since_cm;
126 size_t _bytes_allocated_during_cm;
127 size_t _bytes_allocated_during_cm_start;
128 size_t _max_allocated_gc;
129 size_t _allocated_last_gc;
130 size_t _used_start_gc;
131
132 unsigned int _concurrent_mark_in_progress;
133
134 bool _full_gc_in_progress;
135
136 unsigned int _evacuation_in_progress;
137 bool _need_update_refs;
138 bool _need_reset_bitmaps;
139
224 inline oop maybe_update_oop_ref(T* p);
225
226 void recycle_dirty_regions();
227
228 void start_concurrent_marking();
229 void stop_concurrent_marking();
230 inline bool concurrent_mark_in_progress();
231 static address concurrent_mark_in_progress_addr();
232
233 void prepare_for_concurrent_evacuation();
234 void evacuate_and_update_roots();
235 inline bool is_evacuation_in_progress();
236 void set_evacuation_in_progress(bool in_progress);
237
238 void set_full_gc_in_progress(bool in_progress);
239 bool is_full_gc_in_progress() const;
240
241 inline bool need_update_refs() const;
242 void set_need_update_refs(bool update_refs);
243
244 inline bool region_in_collection_set(size_t region_index) const;
245
246 void set_region_in_collection_set(size_t region_index, bool b);
247
248 // Mainly there to avoid accidentally calling the templated
249 // method below with ShenandoahHeapRegion* which would be *wrong*.
250 inline bool in_collection_set(ShenandoahHeapRegion* r) const;
251
252 template <class T>
253 inline bool in_collection_set(T obj) const;
254
255 void clear_cset_fast_test();
256
257 inline bool allocated_after_next_mark_start(HeapWord* addr) const;
258 void set_next_top_at_mark_start(HeapWord* region_base, HeapWord* addr);
259 HeapWord* next_top_at_mark_start(HeapWord* region_base);
260
261 inline bool allocated_after_complete_mark_start(HeapWord* addr) const;
262 void set_complete_top_at_mark_start(HeapWord* region_base, HeapWord* addr);
263 HeapWord* complete_top_at_mark_start(HeapWord* region_base);
264
265 inline oop evacuate_object(oop src, Thread* thread);
266 inline bool cancelled_concgc() const;
267 void clear_cancelled_concgc();
268
269 ShenandoahHeapRegionSet* regions() { return _ordered_regions;}
270 ShenandoahHeapRegionSet* sorted_regions() { return _sorted_regions;}
271 ShenandoahFreeSet* free_regions();
272 void clear_free_regions();
273 void add_free_region(ShenandoahHeapRegion* r);
274
275 void increase_used(size_t bytes);
276 void decrease_used(size_t bytes);
277
278 void set_used(size_t bytes);
279 size_t calculateUsed();
280
281 void reset_next_mark_bitmap(WorkGang* gang);
282 void reset_complete_mark_bitmap(WorkGang* gang);
283
284 CMBitMap* complete_mark_bit_map();
285 CMBitMap* next_mark_bit_map();
286 inline bool is_marked_complete(oop obj) const;
287 inline bool mark_next(oop obj) const;
288 inline bool is_marked_next(oop obj) const;
289 bool is_next_bitmap_clear();
290 bool is_complete_bitmap_clear_range(HeapWord* start, HeapWord* end);
291
292 void parallel_evacuate_region(ShenandoahHeapRegion* from_region);
293
294 template <class T>
295 inline oop update_oop_ref_not_null(T* p, oop obj);
296
297 void print_heap_regions(outputStream* st = tty) const;
298 void print_all_refs(const char* prefix);
299 void print_heap_locations(HeapWord* start, HeapWord* end);
300
301 size_t bytes_allocated_since_cm();
302 void set_bytes_allocated_since_cm(size_t bytes);
303
304 size_t max_allocated_gc();
305
306 void reclaim_humongous_region_at(ShenandoahHeapRegion* r);
307
308 VirtualSpace* storage() const;
309
310 ShenandoahMonitoringSupport* monitoring_support();
319 uint max_workers();
320 uint max_parallel_workers();
321
322 void do_evacuation();
323 ShenandoahHeapRegion* next_compaction_region(const ShenandoahHeapRegion* r);
324
325 void heap_region_iterate(ShenandoahHeapRegionClosure* blk, bool skip_dirty_regions = false, bool skip_humongous_continuation = false) const;
326
327 void verify_heap_after_evacuation();
328
329 // Delete entries for dead interned string and clean up unreferenced symbols
330 // in symbol table, possibly in parallel.
331 void unlink_string_and_symbol_table(BoolObjectClosure* is_alive, bool unlink_strings = true, bool unlink_symbols = true);
332
333 size_t num_regions();
334 size_t max_regions();
335
336 // TODO: consider moving this into ShenandoahHeapRegion.
337
338 template<class T>
339 inline void marked_object_iterate(ShenandoahHeapRegion* region, T* cl);
340
341 GCTimer* gc_timer() const;
342
343 void swap_mark_bitmaps();
344
345 private:
346 HeapWord* allocate_new_tlab(size_t word_size, bool mark);
347 HeapWord* allocate_memory(size_t word_size, bool evacuating);
348 // Shenandoah functionality.
349 inline HeapWord* allocate_from_gclab(Thread* thread, size_t size);
350 HeapWord* allocate_from_gclab_slow(Thread* thread, size_t size);
351 HeapWord* allocate_new_gclab(size_t word_size);
352
353 void roots_iterate(OopClosure* cl);
354
355 template<class T>
356 inline void do_marked_object(CMBitMap* bitmap, T* cl, oop obj);
357
358 ShenandoahConcurrentThread* concurrent_thread() { return _concurrent_gc_thread; }
359
360 inline bool mark_next_no_checks(oop obj) const;
361
362 void parallel_evacuate();
363
364 template <class T>
365 inline oop maybe_update_oop_ref_not_null(T* p, oop obj);
366
367 inline oop atomic_compare_exchange_oop(oop n, narrowOop* addr, oop c);
368 inline oop atomic_compare_exchange_oop(oop n, oop* addr, oop c);
369
370 void evacuate_region(ShenandoahHeapRegion* from_region, ShenandoahHeapRegion* to_region);
371
372 #ifdef ASSERT
373 void verify_evacuated_region(ShenandoahHeapRegion* from_region);
374 #endif
375
376 inline void copy_object(oop p, HeapWord* s, size_t words);
377 void verify_copy(oop p, oop c);
378 void verify_heap_size_consistency();
379 void verify_heap_after_marking();
380 void verify_heap_after_update_refs();
381 void verify_regions_after_update_refs();
382
383 void ref_processing_init();
384
385 GCTracer* tracer();
386 ShenandoahCollectionSet* collection_set() { return _collection_set; }
387
388 bool call_from_write_barrier(bool evacuating);
389 bool check_grow_heap();
390 void grow_heap_by(size_t num_regions);
391 void ensure_new_regions(size_t num_new_regions);
392
393 void verify_evacuation(ShenandoahHeapRegion* from_region);
394 void set_concurrent_mark_in_progress(bool in_progress);
|