1 /*
2  * Copyright (c) 2013, 2020, Red Hat, Inc. All rights reserved.
3  *
4  * This code is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 2 only, as
6  * published by the Free Software Foundation.
7  *
8  * This code is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11  * version 2 for more details (a copy is included in the LICENSE file that
12  * accompanied this code).
13  *
14  * You should have received a copy of the GNU General Public License version
15  * 2 along with this work; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17  *
18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19  * or visit www.oracle.com if you need additional information or have any
20  * questions.
21  *
22  */
23 
24 #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHHEAP_HPP
25 #define SHARE_GC_SHENANDOAH_SHENANDOAHHEAP_HPP
26 
27 #include "gc/shared/markBitMap.hpp"
28 #include "gc/shared/softRefPolicy.hpp"
29 #include "gc/shared/collectedHeap.hpp"
30 #include "gc/shenandoah/shenandoahAsserts.hpp"
31 #include "gc/shenandoah/shenandoahAllocRequest.hpp"
32 #include "gc/shenandoah/shenandoahLock.hpp"
33 #include "gc/shenandoah/shenandoahEvacOOMHandler.hpp"
34 #include "gc/shenandoah/shenandoahPadding.hpp"
35 #include "gc/shenandoah/shenandoahSharedVariables.hpp"
36 #include "gc/shenandoah/shenandoahUnload.hpp"
37 #include "services/memoryManager.hpp"
38 #include "utilities/globalDefinitions.hpp"
39 
40 class ConcurrentGCTimer;
41 class ReferenceProcessor;
42 class ShenandoahCollectorPolicy;
43 class ShenandoahControlThread;
44 class ShenandoahGCSession;
45 class ShenandoahGCStateResetter;
46 class ShenandoahHeuristics;
47 class ShenandoahMarkingContext;
48 class ShenandoahMarkCompact;
49 class ShenandoahMode;
50 class ShenandoahPhaseTimings;
51 class ShenandoahHeap;
52 class ShenandoahHeapRegion;
53 class ShenandoahHeapRegionClosure;
54 class ShenandoahCollectionSet;
55 class ShenandoahFreeSet;
56 class ShenandoahConcurrentMark;
57 class ShenandoahMarkCompact;
58 class ShenandoahMonitoringSupport;
59 class ShenandoahPacer;
60 class ShenandoahVerifier;
61 class ShenandoahWorkGang;
62 class VMStructs;
63 
64 // Used for buffering per-region liveness data.
65 // Needed since ShenandoahHeapRegion uses atomics to update liveness.
66 // The ShenandoahHeap array has max-workers elements, each of which is an array of
67 // uint16_t * max_regions. The choice of uint16_t is not accidental:
68 // there is a tradeoff between static/dynamic footprint that translates
69 // into cache pressure (which is already high during marking), and
70 // too many atomic updates. uint32_t is too large, uint8_t is too small.
71 typedef uint16_t ShenandoahLiveData;
72 #define SHENANDOAH_LIVEDATA_MAX ((ShenandoahLiveData)-1)
73 
74 class ShenandoahRegionIterator : public StackObj {
75 private:
76   ShenandoahHeap* _heap;
77 
78   shenandoah_padding(0);
79   volatile size_t _index;
80   shenandoah_padding(1);
81 
82   // No implicit copying: iterators should be passed by reference to capture the state
83   NONCOPYABLE(ShenandoahRegionIterator);
84 
85 public:
86   ShenandoahRegionIterator();
87   ShenandoahRegionIterator(ShenandoahHeap* heap);
88 
89   // Reset iterator to default state
90   void reset();
91 
92   // Returns next region, or NULL if there are no more regions.
93   // This is multi-thread-safe.
94   inline ShenandoahHeapRegion* next();
95 
96   // This is *not* MT safe. However, in the absence of multithreaded access, it
97   // can be used to determine if there is more work to do.
98   bool has_next() const;
99 };
100 
101 class ShenandoahHeapRegionClosure : public StackObj {
102 public:
103   virtual void heap_region_do(ShenandoahHeapRegion* r) = 0;
is_thread_safe()104   virtual bool is_thread_safe() { return false; }
105 };
106 
107 #ifdef ASSERT
108 class ShenandoahAssertToSpaceClosure : public OopClosure {
109 private:
110   template <class T>
111   void do_oop_work(T* p);
112 public:
113   void do_oop(narrowOop* p);
114   void do_oop(oop* p);
115 };
116 #endif
117 
118 typedef ShenandoahLock    ShenandoahHeapLock;
119 typedef ShenandoahLocker  ShenandoahHeapLocker;
120 
121 // Shenandoah GC is low-pause concurrent GC that uses Brooks forwarding pointers
122 // to encode forwarding data. See BrooksPointer for details on forwarding data encoding.
123 // See ShenandoahControlThread for GC cycle structure.
124 //
125 class ShenandoahHeap : public CollectedHeap {
126   friend class ShenandoahAsserts;
127   friend class VMStructs;
128   friend class ShenandoahGCSession;
129   friend class ShenandoahGCStateResetter;
130 
131 // ---------- Locks that guard important data structures in Heap
132 //
133 private:
134   ShenandoahHeapLock _lock;
135 
136 public:
lock()137   ShenandoahHeapLock* lock() {
138     return &_lock;
139   }
140 
141 // ---------- Initialization, termination, identification, printing routines
142 //
143 private:
144   static ShenandoahHeap* _heap;
145 
146 public:
147   static ShenandoahHeap* heap();
148 
name() const149   const char* name()          const { return "Shenandoah"; }
kind() const150   ShenandoahHeap::Name kind() const { return CollectedHeap::Shenandoah; }
151 
152   ShenandoahHeap(ShenandoahCollectorPolicy* policy);
153   jint initialize();
154   void post_initialize();
155   void initialize_heuristics();
156 
157   void initialize_serviceability();
158 
159   void print_on(outputStream* st)              const;
160   void print_extended_on(outputStream *st)     const;
161   void print_tracing_info()                    const;
162   void print_gc_threads_on(outputStream* st)   const;
163   void print_heap_regions_on(outputStream* st) const;
164 
165   void stop();
166 
167   void prepare_for_verify();
168   void verify(VerifyOption vo);
169 
170 // ---------- Heap counters and metrics
171 //
172 private:
173            size_t _initial_size;
174            size_t _minimum_size;
175   shenandoah_padding(0);
176   volatile size_t _used;
177   volatile size_t _committed;
178   volatile size_t _bytes_allocated_since_gc_start;
179   shenandoah_padding(1);
180 
181 public:
182   void increase_used(size_t bytes);
183   void decrease_used(size_t bytes);
184   void set_used(size_t bytes);
185 
186   void increase_committed(size_t bytes);
187   void decrease_committed(size_t bytes);
188   void increase_allocated(size_t bytes);
189 
190   size_t bytes_allocated_since_gc_start();
191   void reset_bytes_allocated_since_gc_start();
192 
193   size_t min_capacity()     const;
194   size_t max_capacity()     const;
195   size_t initial_capacity() const;
196   size_t capacity()         const;
197   size_t used()             const;
198   size_t committed()        const;
199 
200 // ---------- Workers handling
201 //
202 private:
203   uint _max_workers;
204   ShenandoahWorkGang* _workers;
205   ShenandoahWorkGang* _safepoint_workers;
206 
207 public:
208   uint max_workers();
209   void assert_gc_workers(uint nworker) NOT_DEBUG_RETURN;
210 
211   WorkGang* workers() const;
212   WorkGang* get_safepoint_workers();
213 
214   void gc_threads_do(ThreadClosure* tcl) const;
215 
216 // ---------- Heap regions handling machinery
217 //
218 private:
219   MemRegion _heap_region;
220   bool      _heap_region_special;
221   size_t    _num_regions;
222   ShenandoahHeapRegion** _regions;
223   ShenandoahRegionIterator _update_refs_iterator;
224 
225 public:
226 
base() const227   inline HeapWord* base() const { return _heap_region.start(); }
228 
num_regions() const229   inline size_t num_regions() const { return _num_regions; }
is_heap_region_special()230   inline bool is_heap_region_special() { return _heap_region_special; }
231 
232   inline ShenandoahHeapRegion* const heap_region_containing(const void* addr) const;
233   inline size_t heap_region_index_containing(const void* addr) const;
234 
235   inline ShenandoahHeapRegion* const get_region(size_t region_idx) const;
236 
237   void heap_region_iterate(ShenandoahHeapRegionClosure* blk) const;
238   void parallel_heap_region_iterate(ShenandoahHeapRegionClosure* blk) const;
239 
240 // ---------- GC state machinery
241 //
242 // GC state describes the important parts of collector state, that may be
243 // used to make barrier selection decisions in the native and generated code.
244 // Multiple bits can be set at once.
245 //
246 // Important invariant: when GC state is zero, the heap is stable, and no barriers
247 // are required.
248 //
249 public:
250   enum GCStateBitPos {
251     // Heap has forwarded objects: needs LRB barriers.
252     HAS_FORWARDED_BITPOS   = 0,
253 
254     // Heap is under marking: needs SATB barriers.
255     MARKING_BITPOS    = 1,
256 
257     // Heap is under evacuation: needs LRB barriers. (Set together with HAS_FORWARDED)
258     EVACUATION_BITPOS = 2,
259 
260     // Heap is under updating: needs no additional barriers.
261     UPDATEREFS_BITPOS = 3,
262   };
263 
264   enum GCState {
265     STABLE        = 0,
266     HAS_FORWARDED = 1 << HAS_FORWARDED_BITPOS,
267     MARKING       = 1 << MARKING_BITPOS,
268     EVACUATION    = 1 << EVACUATION_BITPOS,
269     UPDATEREFS    = 1 << UPDATEREFS_BITPOS,
270   };
271 
272 private:
273   ShenandoahSharedBitmap _gc_state;
274   ShenandoahSharedFlag   _degenerated_gc_in_progress;
275   ShenandoahSharedFlag   _full_gc_in_progress;
276   ShenandoahSharedFlag   _full_gc_move_in_progress;
277   ShenandoahSharedFlag   _progress_last_gc;
278   ShenandoahSharedFlag   _concurrent_root_in_progress;
279 
280   void set_gc_state_all_threads(char state);
281   void set_gc_state_mask(uint mask, bool value);
282 
283 public:
284   char gc_state() const;
285   static address gc_state_addr();
286 
287   void set_concurrent_mark_in_progress(bool in_progress);
288   void set_evacuation_in_progress(bool in_progress);
289   void set_update_refs_in_progress(bool in_progress);
290   void set_degenerated_gc_in_progress(bool in_progress);
291   void set_full_gc_in_progress(bool in_progress);
292   void set_full_gc_move_in_progress(bool in_progress);
293   void set_has_forwarded_objects(bool cond);
294   void set_concurrent_root_in_progress(bool cond);
295 
296   inline bool is_stable() const;
297   inline bool is_idle() const;
298   inline bool is_concurrent_mark_in_progress() const;
299   inline bool is_update_refs_in_progress() const;
300   inline bool is_evacuation_in_progress() const;
301   inline bool is_degenerated_gc_in_progress() const;
302   inline bool is_full_gc_in_progress() const;
303   inline bool is_full_gc_move_in_progress() const;
304   inline bool has_forwarded_objects() const;
305   inline bool is_gc_in_progress_mask(uint mask) const;
306   inline bool is_stw_gc_in_progress() const;
307   inline bool is_concurrent_root_in_progress() const;
308 
309 // ---------- GC cancellation and degeneration machinery
310 //
311 // Cancelled GC flag is used to notify concurrent phases that they should terminate.
312 //
313 public:
314   enum ShenandoahDegenPoint {
315     _degenerated_unset,
316     _degenerated_outside_cycle,
317     _degenerated_mark,
318     _degenerated_evac,
319     _degenerated_updaterefs,
320     _DEGENERATED_LIMIT
321   };
322 
degen_point_to_string(ShenandoahDegenPoint point)323   static const char* degen_point_to_string(ShenandoahDegenPoint point) {
324     switch (point) {
325       case _degenerated_unset:
326         return "<UNSET>";
327       case _degenerated_outside_cycle:
328         return "Outside of Cycle";
329       case _degenerated_mark:
330         return "Mark";
331       case _degenerated_evac:
332         return "Evacuation";
333       case _degenerated_updaterefs:
334         return "Update Refs";
335       default:
336         ShouldNotReachHere();
337         return "ERROR";
338     }
339   };
340 
341 private:
342   enum CancelState {
343     // Normal state. GC has not been cancelled and is open for cancellation.
344     // Worker threads can suspend for safepoint.
345     CANCELLABLE,
346 
347     // GC has been cancelled. Worker threads can not suspend for
348     // safepoint but must finish their work as soon as possible.
349     CANCELLED,
350 
351     // GC has not been cancelled and must not be cancelled. At least
352     // one worker thread checks for pending safepoint and may suspend
353     // if a safepoint is pending.
354     NOT_CANCELLED
355   };
356 
357   ShenandoahSharedEnumFlag<CancelState> _cancelled_gc;
358   bool try_cancel_gc();
359 
360 public:
361   static address cancelled_gc_addr();
362 
363   inline bool cancelled_gc() const;
364   inline bool check_cancelled_gc_and_yield(bool sts_active = true);
365 
366   inline void clear_cancelled_gc();
367 
368   void cancel_gc(GCCause::Cause cause);
369 
370 // ---------- GC operations entry points
371 //
372 public:
373   // Entry points to STW GC operations, these cause a related safepoint, that then
374   // call the entry method below
375   void vmop_entry_init_mark();
376   void vmop_entry_final_mark();
377   void vmop_entry_init_updaterefs();
378   void vmop_entry_final_updaterefs();
379   void vmop_entry_full(GCCause::Cause cause);
380   void vmop_degenerated(ShenandoahDegenPoint point);
381 
382   // Entry methods to normally STW GC operations. These set up logging, monitoring
383   // and workers for net VM operation
384   void entry_init_mark();
385   void entry_final_mark();
386   void entry_init_updaterefs();
387   void entry_final_updaterefs();
388   void entry_full(GCCause::Cause cause);
389   void entry_degenerated(int point);
390 
391   // Entry methods to normally concurrent GC operations. These set up logging, monitoring
392   // for concurrent operation.
393   void entry_reset();
394   void entry_mark();
395   void entry_preclean();
396   void entry_roots();
397   void entry_cleanup_early();
398   void entry_evac();
399   void entry_updaterefs();
400   void entry_cleanup_complete();
401   void entry_uncommit(double shrink_before);
402 
403 private:
404   // Actual work for the phases
405   void op_init_mark();
406   void op_final_mark();
407   void op_init_updaterefs();
408   void op_final_updaterefs();
409   void op_full(GCCause::Cause cause);
410   void op_degenerated(ShenandoahDegenPoint point);
411   void op_degenerated_fail();
412   void op_degenerated_futile();
413 
414   void op_reset();
415   void op_mark();
416   void op_preclean();
417   void op_roots();
418   void op_cleanup_early();
419   void op_conc_evac();
420   void op_stw_evac();
421   void op_updaterefs();
422   void op_cleanup_complete();
423   void op_uncommit(double shrink_before);
424 
425   // Messages for GC trace events, they have to be immortal for
426   // passing around the logging/tracing systems
427   const char* init_mark_event_message() const;
428   const char* final_mark_event_message() const;
429   const char* conc_mark_event_message() const;
430   const char* degen_event_message(ShenandoahDegenPoint point) const;
431 
432 // ---------- GC subsystems
433 //
434 private:
435   ShenandoahControlThread*   _control_thread;
436   ShenandoahCollectorPolicy* _shenandoah_policy;
437   ShenandoahMode*            _gc_mode;
438   ShenandoahHeuristics*      _heuristics;
439   ShenandoahFreeSet*         _free_set;
440   ShenandoahConcurrentMark*  _scm;
441   ShenandoahMarkCompact*     _full_gc;
442   ShenandoahPacer*           _pacer;
443   ShenandoahVerifier*        _verifier;
444 
445   ShenandoahPhaseTimings*    _phase_timings;
446 
control_thread()447   ShenandoahControlThread*   control_thread()          { return _control_thread;    }
full_gc()448   ShenandoahMarkCompact*     full_gc()                 { return _full_gc;           }
449 
450 public:
shenandoah_policy() const451   ShenandoahCollectorPolicy* shenandoah_policy() const { return _shenandoah_policy; }
heuristics() const452   ShenandoahHeuristics*      heuristics()        const { return _heuristics;        }
free_set() const453   ShenandoahFreeSet*         free_set()          const { return _free_set;          }
concurrent_mark()454   ShenandoahConcurrentMark*  concurrent_mark()         { return _scm;               }
pacer() const455   ShenandoahPacer*           pacer()             const { return _pacer;             }
456 
phase_timings() const457   ShenandoahPhaseTimings*    phase_timings()     const { return _phase_timings;     }
458 
459   ShenandoahVerifier*        verifier();
460 
461 // ---------- VM subsystem bindings
462 //
463 private:
464   ShenandoahMonitoringSupport* _monitoring_support;
465   MemoryPool*                  _memory_pool;
466   GCMemoryManager              _stw_memory_manager;
467   GCMemoryManager              _cycle_memory_manager;
468   ConcurrentGCTimer*           _gc_timer;
469   SoftRefPolicy                _soft_ref_policy;
470 
471   // For exporting to SA
472   int                          _log_min_obj_alignment_in_bytes;
473 public:
monitoring_support()474   ShenandoahMonitoringSupport* monitoring_support() { return _monitoring_support;    }
cycle_memory_manager()475   GCMemoryManager* cycle_memory_manager()           { return &_cycle_memory_manager; }
stw_memory_manager()476   GCMemoryManager* stw_memory_manager()             { return &_stw_memory_manager;   }
soft_ref_policy()477   SoftRefPolicy* soft_ref_policy()                  { return &_soft_ref_policy;      }
478 
479   GrowableArray<GCMemoryManager*> memory_managers();
480   GrowableArray<MemoryPool*> memory_pools();
481   MemoryUsage memory_usage();
482   GCTracer* tracer();
483   ConcurrentGCTimer* gc_timer() const;
484 
485 // ---------- Reference processing
486 //
487 private:
488   AlwaysTrueClosure    _subject_to_discovery;
489   ReferenceProcessor*  _ref_processor;
490   ShenandoahSharedFlag _process_references;
491 
492   void ref_processing_init();
493 
494 public:
ref_processor()495   ReferenceProcessor* ref_processor() { return _ref_processor; }
496   void set_process_references(bool pr);
497   bool process_references() const;
498 
499 // ---------- Class Unloading
500 //
501 private:
502   ShenandoahSharedFlag _unload_classes;
503   ShenandoahUnload     _unloader;
504 
505 public:
506   void set_unload_classes(bool uc);
507   bool unload_classes() const;
508 
509   // Perform STW class unloading and weak root cleaning
510   void parallel_cleaning(bool full_gc);
511 
512 private:
513   void stw_unload_classes(bool full_gc);
514   void stw_process_weak_roots(bool full_gc);
515 
516   // Prepare concurrent root processing
517   void prepare_concurrent_roots();
518   // Prepare and finish concurrent unloading
519   void prepare_concurrent_unloading();
520   void finish_concurrent_unloading();
521 
522 // ---------- Generic interface hooks
523 // Minor things that super-interface expects us to implement to play nice with
524 // the rest of runtime. Some of the things here are not required to be implemented,
525 // and can be stubbed out.
526 //
527 public:
528   AdaptiveSizePolicy* size_policy() shenandoah_not_implemented_return(NULL);
529   bool is_maximal_no_gc() const shenandoah_not_implemented_return(false);
530 
531   bool is_in(const void* p) const;
532 
reserved_region() const533   MemRegion reserved_region() const { return _reserved; }
is_in_reserved(const void * addr) const534   bool is_in_reserved(const void* addr) const { return _reserved.contains(addr); }
535 
536   void collect(GCCause::Cause cause);
537   void do_full_collection(bool clear_all_soft_refs);
538 
539   // Used for parsing heap during error printing
540   HeapWord* block_start(const void* addr) const;
541   bool block_is_obj(const HeapWord* addr) const;
542   bool print_location(outputStream* st, void* addr) const;
543 
544   // Used for native heap walkers: heap dumpers, mostly
545   void object_iterate(ObjectClosure* cl);
546 
547   // Keep alive an object that was loaded with AS_NO_KEEPALIVE.
548   void keep_alive(oop obj);
549 
550   // Used by RMI
551   jlong millis_since_last_gc();
552 
553 // ---------- Safepoint interface hooks
554 //
555 public:
556   void safepoint_synchronize_begin();
557   void safepoint_synchronize_end();
558 
559 // ---------- Code roots handling hooks
560 //
561 public:
562   void register_nmethod(nmethod* nm);
563   void unregister_nmethod(nmethod* nm);
564   void flush_nmethod(nmethod* nm);
verify_nmethod(nmethod * nm)565   void verify_nmethod(nmethod* nm) {}
566 
567 // ---------- Pinning hooks
568 //
569 public:
570   // Shenandoah supports per-object (per-region) pinning
supports_object_pinning() const571   bool supports_object_pinning() const { return true; }
572 
573   oop pin_object(JavaThread* thread, oop obj);
574   void unpin_object(JavaThread* thread, oop obj);
575 
576   void sync_pinned_region_status();
577   void assert_pinned_region_status() NOT_DEBUG_RETURN;
578 
579 // ---------- Allocation support
580 //
581 private:
582   HeapWord* allocate_memory_under_lock(ShenandoahAllocRequest& request, bool& in_new_region);
583   inline HeapWord* allocate_from_gclab(Thread* thread, size_t size);
584   HeapWord* allocate_from_gclab_slow(Thread* thread, size_t size);
585   HeapWord* allocate_new_gclab(size_t min_size, size_t word_size, size_t* actual_size);
586   void retire_and_reset_gclabs();
587 
588 public:
589   HeapWord* allocate_memory(ShenandoahAllocRequest& request);
590   HeapWord* mem_allocate(size_t size, bool* what);
591   MetaWord* satisfy_failed_metadata_allocation(ClassLoaderData* loader_data,
592                                                size_t size,
593                                                Metaspace::MetadataType mdtype);
594 
595   void notify_mutator_alloc_words(size_t words, bool waste);
596 
597   // Shenandoah supports TLAB allocation
supports_tlab_allocation() const598   bool supports_tlab_allocation() const { return true; }
599 
600   HeapWord* allocate_new_tlab(size_t min_size, size_t requested_size, size_t* actual_size);
601   size_t tlab_capacity(Thread *thr) const;
602   size_t unsafe_max_tlab_alloc(Thread *thread) const;
603   size_t max_tlab_size() const;
604   size_t tlab_used(Thread* ignored) const;
605 
606   void resize_tlabs();
607 
608   void ensure_parsability(bool retire_tlabs);
609   void make_parsable(bool retire_tlabs);
610 
611 // ---------- Marking support
612 //
613 private:
614   ShenandoahMarkingContext* _marking_context;
615   MemRegion  _bitmap_region;
616   MemRegion  _aux_bitmap_region;
617   MarkBitMap _verification_bit_map;
618   MarkBitMap _aux_bit_map;
619 
620   size_t _bitmap_size;
621   size_t _bitmap_regions_per_slice;
622   size_t _bitmap_bytes_per_slice;
623 
624   size_t _pretouch_heap_page_size;
625   size_t _pretouch_bitmap_page_size;
626 
627   bool _bitmap_region_special;
628   bool _aux_bitmap_region_special;
629 
630   ShenandoahLiveData** _liveness_cache;
631 
632 public:
633   inline ShenandoahMarkingContext* complete_marking_context() const;
634   inline ShenandoahMarkingContext* marking_context() const;
635   inline void mark_complete_marking_context();
636   inline void mark_incomplete_marking_context();
637 
638   template<class T>
639   inline void marked_object_iterate(ShenandoahHeapRegion* region, T* cl);
640 
641   template<class T>
642   inline void marked_object_iterate(ShenandoahHeapRegion* region, T* cl, HeapWord* limit);
643 
644   template<class T>
645   inline void marked_object_oop_iterate(ShenandoahHeapRegion* region, T* cl, HeapWord* limit);
646 
647   void reset_mark_bitmap();
648 
649   // SATB barriers hooks
650   template<bool RESOLVE>
651   inline bool requires_marking(const void* entry) const;
652   void force_satb_flush_all_threads();
653 
654   // Support for bitmap uncommits
655   bool commit_bitmap_slice(ShenandoahHeapRegion *r);
656   bool uncommit_bitmap_slice(ShenandoahHeapRegion *r);
657   bool is_bitmap_slice_committed(ShenandoahHeapRegion* r, bool skip_self = false);
658 
659   // Liveness caching support
660   ShenandoahLiveData* get_liveness_cache(uint worker_id);
661   void flush_liveness_cache(uint worker_id);
662 
pretouch_heap_page_size()663   size_t pretouch_heap_page_size() { return _pretouch_heap_page_size; }
664 
665 // ---------- Evacuation support
666 //
667 private:
668   ShenandoahCollectionSet* _collection_set;
669   ShenandoahEvacOOMHandler _oom_evac_handler;
670 
671   void evacuate_and_update_roots();
672 
673 public:
674   static address in_cset_fast_test_addr();
675 
collection_set() const676   ShenandoahCollectionSet* collection_set() const { return _collection_set; }
677 
678   // Checks if object is in the collection set.
679   inline bool in_collection_set(oop obj) const;
680 
681   // Checks if location is in the collection set. Can be interior pointer, not the oop itself.
682   inline bool in_collection_set_loc(void* loc) const;
683 
684   // Evacuates object src. Returns the evacuated object, either evacuated
685   // by this thread, or by some other thread.
686   inline oop evacuate_object(oop src, Thread* thread);
687 
688   // Call before/after evacuation.
689   void enter_evacuation();
690   void leave_evacuation();
691 
692 // ---------- Helper functions
693 //
694 public:
695   template <class T>
696   inline oop evac_update_with_forwarded(T* p);
697 
698   template <class T>
699   inline oop maybe_update_with_forwarded(T* p);
700 
701   template <class T>
702   inline oop maybe_update_with_forwarded_not_null(T* p, oop obj);
703 
704   template <class T>
705   inline oop update_with_forwarded_not_null(T* p, oop obj);
706 
707   static inline oop cas_oop(oop n, narrowOop* addr, oop c);
708   static inline oop cas_oop(oop n, oop* addr, oop c);
709   static inline oop cas_oop(oop n, narrowOop* addr, narrowOop c);
710 
711   void trash_humongous_region_at(ShenandoahHeapRegion *r);
712 
713   void deduplicate_string(oop str);
714 
715 private:
716   void trash_cset_regions();
717   void update_heap_references(bool concurrent);
718 
719 // ---------- Testing helpers functions
720 //
721 private:
722   ShenandoahSharedFlag _inject_alloc_failure;
723 
724   void try_inject_alloc_failure();
725   bool should_inject_alloc_failure();
726 };
727 
728 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHHEAP_HPP
729