1 /*
   2  * Copyright (c) 2013, 2018, 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_VM_GC_SHENANDOAH_SHENANDOAHHEAP_HPP
  25 #define SHARE_VM_GC_SHENANDOAH_SHENANDOAHHEAP_HPP
  26 
  27 #include "gc_implementation/shared/markBitMap.hpp"
  28 #include "gc_implementation/shenandoah/shenandoahAsserts.hpp"
  29 #include "gc_implementation/shenandoah/shenandoahAllocRequest.hpp"
  30 #include "gc_implementation/shenandoah/shenandoahLock.hpp"
  31 #include "gc_implementation/shenandoah/shenandoahEvacOOMHandler.hpp"
  32 #include "gc_implementation/shenandoah/shenandoahSharedVariables.hpp"
  33 
  34 class ConcurrentGCTimer;
  35 
  36 class ShenandoahAllocTracker;
  37 class ShenandoahCollectionSet;
  38 class ShenandoahCollectorPolicy;
  39 class ShenandoahConcurrentMark;
  40 class ShenandoahControlThread;
  41 class ShenandoahGCSession;
  42 class ShenandoahFreeSet;
  43 class ShenandoahHeapRegion;
  44 class ShenandoahHeapRegionClosure;
  45 class ShenandoahMarkCompact;
  46 class ShenandoahMonitoringSupport;
  47 class ShenandoahHeuristics;
  48 class ShenandoahMarkingContext;
  49 class ShenandoahMode;
  50 class ShenandoahPhaseTimings;
  51 class ShenandoahPacer;
  52 class ShenandoahTraversalGC;
  53 class ShenandoahVerifier;
  54 class ShenandoahWorkGang;
  55 class VMStructs;
  56 
  57 class ShenandoahRegionIterator : public StackObj {
  58 private:
  59   ShenandoahHeap* _heap;
  60 
  61   char _pad0[DEFAULT_CACHE_LINE_SIZE];
  62   volatile jint _index;
  63   char _pad1[DEFAULT_CACHE_LINE_SIZE];
  64 
  65   // No implicit copying: iterators should be passed by reference to capture the state
  66   ShenandoahRegionIterator(const ShenandoahRegionIterator& that);
  67   ShenandoahRegionIterator& operator=(const ShenandoahRegionIterator& o);
  68 
  69 public:
  70   ShenandoahRegionIterator();
  71   ShenandoahRegionIterator(ShenandoahHeap* heap);
  72 
  73   // Reset iterator to default state
  74   void reset();
  75 
  76   // Returns next region, or NULL if there are no more regions.
  77   // This is multi-thread-safe.
  78   inline ShenandoahHeapRegion* next();
  79 
  80   // This is *not* MT safe. However, in the absence of multithreaded access, it
  81   // can be used to determine if there is more work to do.
  82   bool has_next() const;
  83 };
  84 
  85 class ShenandoahHeapRegionClosure : public StackObj {
  86 public:
  87   virtual void heap_region_do(ShenandoahHeapRegion* r) = 0;
  88   virtual bool is_thread_safe() { return false; }
  89 };
  90 
  91 #ifdef ASSERT
  92 class ShenandoahAssertToSpaceClosure : public OopClosure {
  93 private:
  94   template <class T>
  95   void do_oop_nv(T* p);
  96 public:
  97   void do_oop(narrowOop* p);
  98   void do_oop(oop* p);
  99 };
 100 #endif
 101 
 102 typedef ShenandoahLock    ShenandoahHeapLock;
 103 typedef ShenandoahLocker  ShenandoahHeapLocker;
 104 
 105 // Shenandoah GC is low-pause concurrent GC that uses Brooks forwarding pointers
 106 // to encode forwarding data. See BrooksPointer for details on forwarding data encoding.
 107 // See ShenandoahControlThread for GC cycle structure.
 108 //
 109 class ShenandoahHeap : public SharedHeap {
 110   friend class ShenandoahAsserts;
 111   friend class VMStructs;
 112   friend class ShenandoahGCSession;
 113 
 114 // ---------- Locks that guard important data structures in Heap
 115 //
 116 private:
 117   ShenandoahHeapLock _lock;
 118 
 119 public:
 120   ShenandoahHeapLock* lock() {
 121     return &_lock;
 122   }
 123 
 124   void assert_heaplock_owned_by_current_thread()     NOT_DEBUG_RETURN;
 125   void assert_heaplock_not_owned_by_current_thread() NOT_DEBUG_RETURN;
 126   void assert_heaplock_or_safepoint()                NOT_DEBUG_RETURN;
 127 
 128 // ---------- Initialization, termination, identification, printing routines
 129 //
 130 public:
 131   static ShenandoahHeap* heap();
 132   static ShenandoahHeap* heap_no_check();
 133   static size_t conservative_max_heap_alignment();
 134 
 135   const char* name()          const { return "Shenandoah"; }
 136   ShenandoahHeap::Name kind() const { return CollectedHeap::ShenandoahHeap; }
 137 
 138   ShenandoahHeap(ShenandoahCollectorPolicy* policy);
 139   jint initialize();
 140   void post_initialize();
 141   void initialize_heuristics();
 142 
 143   void print_on(outputStream* st)               const;
 144   void print_extended_on(outputStream *st)      const;
 145   void print_tracing_info()                     const;
 146   void print_gc_threads_on(outputStream* st)    const;
 147   void print_heap_regions_on(outputStream* st)  const;
 148 
 149   void stop();
 150 
 151   void prepare_for_verify();
 152   void verify(bool silent, VerifyOption vo);
 153 
 154 // ---------- Heap counters and metrics
 155 //
 156 private:
 157            size_t _initial_size;
 158            size_t _minimum_size;
 159   char _pad0[DEFAULT_CACHE_LINE_SIZE];
 160   volatile jlong  _used;
 161   volatile size_t _committed;
 162   volatile jlong  _bytes_allocated_since_gc_start;
 163   char _pad1[DEFAULT_CACHE_LINE_SIZE];
 164 
 165 public:
 166   void increase_used(size_t bytes);
 167   void decrease_used(size_t bytes);
 168   void set_used(size_t bytes);
 169 
 170   void increase_committed(size_t bytes);
 171   void decrease_committed(size_t bytes);
 172   void increase_allocated(size_t bytes);
 173 
 174   size_t bytes_allocated_since_gc_start();
 175   void reset_bytes_allocated_since_gc_start();
 176 
 177   size_t min_capacity()     const;
 178   size_t max_capacity()     const;
 179   size_t initial_capacity() const;
 180   size_t capacity()         const;
 181   size_t used()             const;
 182   size_t committed()        const;
 183 
 184 // ---------- Workers handling
 185 //
 186 private:
 187   uint _max_workers;
 188 
 189 public:
 190   uint max_workers();
 191   void assert_gc_workers(uint nworker) NOT_DEBUG_RETURN;
 192 
 193   ShenandoahWorkGang* workers() const;
 194 
 195   void gc_threads_do(ThreadClosure* tcl) const;
 196 
 197 // ---------- Heap regions handling machinery
 198 //
 199 private:
 200   MemRegion _heap_region;
 201   bool      _heap_region_special;
 202   size_t    _num_regions;
 203   ShenandoahHeapRegion** _regions;
 204   ShenandoahRegionIterator _update_refs_iterator;
 205 
 206 public:
 207   inline size_t num_regions() const { return _num_regions; }
 208   inline bool is_heap_region_special() { return _heap_region_special; }
 209 
 210   inline ShenandoahHeapRegion* const heap_region_containing(const void* addr) const;
 211   inline size_t heap_region_index_containing(const void* addr) const;
 212 
 213   inline ShenandoahHeapRegion* const get_region(size_t region_idx) const;
 214 
 215   void heap_region_iterate(ShenandoahHeapRegionClosure* blk) const;
 216   void parallel_heap_region_iterate(ShenandoahHeapRegionClosure* blk) const;
 217 
 218 // ---------- GC state machinery
 219 //
 220 // GC state describes the important parts of collector state, that may be
 221 // used to make barrier selection decisions in the native and generated code.
 222 // Multiple bits can be set at once.
 223 //
 224 // Important invariant: when GC state is zero, the heap is stable, and no barriers
 225 // are required.
 226 //
 227 public:
 228   enum GCStateBitPos {
 229     // Heap has forwarded objects: need RB, ACMP, CAS barriers.
 230     HAS_FORWARDED_BITPOS   = 0,
 231 
 232     // Heap is under marking: needs SATB barriers.
 233     MARKING_BITPOS    = 1,
 234 
 235     // Heap is under evacuation: needs WB barriers. (Set together with UNSTABLE)
 236     EVACUATION_BITPOS = 2,
 237 
 238     // Heap is under updating: needs SVRB/SVWB barriers.
 239     UPDATEREFS_BITPOS = 3,
 240 
 241     // Heap is under traversal collection
 242     TRAVERSAL_BITPOS  = 4
 243   };
 244 
 245   enum GCState {
 246     STABLE        = 0,
 247     HAS_FORWARDED = 1 << HAS_FORWARDED_BITPOS,
 248     MARKING       = 1 << MARKING_BITPOS,
 249     EVACUATION    = 1 << EVACUATION_BITPOS,
 250     UPDATEREFS    = 1 << UPDATEREFS_BITPOS,
 251     TRAVERSAL     = 1 << TRAVERSAL_BITPOS
 252   };
 253 
 254 private:
 255   ShenandoahSharedBitmap _gc_state;
 256   ShenandoahSharedFlag   _degenerated_gc_in_progress;
 257   ShenandoahSharedFlag   _full_gc_in_progress;
 258   ShenandoahSharedFlag   _full_gc_move_in_progress;
 259   ShenandoahSharedFlag   _progress_last_gc;
 260 
 261   void set_gc_state_mask(uint mask, bool value);
 262 
 263 public:
 264   char gc_state();
 265   static address gc_state_addr();
 266 
 267   void set_concurrent_mark_in_progress(bool in_progress);
 268   void set_evacuation_in_progress(bool in_progress);
 269   void set_update_refs_in_progress(bool in_progress);
 270   void set_degenerated_gc_in_progress(bool in_progress);
 271   void set_full_gc_in_progress(bool in_progress);
 272   void set_full_gc_move_in_progress(bool in_progress);
 273   void set_concurrent_traversal_in_progress(bool in_progress);
 274   void set_has_forwarded_objects(bool cond);
 275 
 276   inline bool is_stable() const;
 277   inline bool is_idle() const;
 278   inline bool is_concurrent_mark_in_progress() const;
 279   inline bool is_update_refs_in_progress() const;
 280   inline bool is_evacuation_in_progress() const;
 281   inline bool is_degenerated_gc_in_progress() const;
 282   inline bool is_full_gc_in_progress() const;
 283   inline bool is_full_gc_move_in_progress() const;
 284   inline bool is_concurrent_traversal_in_progress() const;
 285   inline bool has_forwarded_objects() const;
 286   inline bool is_gc_in_progress_mask(uint mask) const;
 287 
 288 // ---------- GC cancellation and degeneration machinery
 289 //
 290 // Cancelled GC flag is used to notify concurrent phases that they should terminate.
 291 //
 292 public:
 293   enum ShenandoahDegenPoint {
 294     _degenerated_unset,
 295     _degenerated_traversal,
 296     _degenerated_outside_cycle,
 297     _degenerated_mark,
 298     _degenerated_evac,
 299     _degenerated_updaterefs,
 300     _DEGENERATED_LIMIT
 301   };
 302 
 303   static const char* degen_point_to_string(ShenandoahDegenPoint point) {
 304     switch (point) {
 305       case _degenerated_unset:
 306         return "<UNSET>";
 307       case _degenerated_traversal:
 308         return "Traversal";
 309       case _degenerated_outside_cycle:
 310         return "Outside of Cycle";
 311       case _degenerated_mark:
 312         return "Mark";
 313       case _degenerated_evac:
 314         return "Evacuation";
 315       case _degenerated_updaterefs:
 316         return "Update Refs";
 317       default:
 318         ShouldNotReachHere();
 319         return "ERROR";
 320     }
 321   };
 322 
 323 private:
 324   ShenandoahSharedFlag _cancelled_gc;
 325   inline bool try_cancel_gc();
 326 
 327 public:
 328   static address cancelled_gc_addr();
 329 
 330   inline bool cancelled_gc() const;
 331 
 332   inline void clear_cancelled_gc();
 333 
 334   void cancel_gc(GCCause::Cause cause);
 335 
 336 // ---------- GC operations entry points
 337 //
 338 public:
 339   // Entry points to STW GC operations, these cause a related safepoint, that then
 340   // call the entry method below
 341   void vmop_entry_init_mark();
 342   void vmop_entry_final_mark();
 343   void vmop_entry_final_evac();
 344   void vmop_entry_init_updaterefs();
 345   void vmop_entry_final_updaterefs();
 346   void vmop_entry_init_traversal();
 347   void vmop_entry_final_traversal();
 348   void vmop_entry_full(GCCause::Cause cause);
 349   void vmop_degenerated(ShenandoahDegenPoint point);
 350 
 351   // Entry methods to normally STW GC operations. These set up logging, monitoring
 352   // and workers for net VM operation
 353   void entry_init_mark();
 354   void entry_final_mark();
 355   void entry_final_evac();
 356   void entry_init_updaterefs();
 357   void entry_final_updaterefs();
 358   void entry_init_traversal();
 359   void entry_final_traversal();
 360   void entry_full(GCCause::Cause cause);
 361   void entry_degenerated(int point);
 362 
 363   // Entry methods to normally concurrent GC operations. These set up logging, monitoring
 364   // for concurrent operation.
 365   void entry_reset();
 366   void entry_mark();
 367   void entry_preclean();
 368   void entry_cleanup();
 369   void entry_evac();
 370   void entry_updaterefs();
 371   void entry_traversal();
 372   void entry_uncommit(double shrink_before);
 373 
 374 private:
 375   // Actual work for the phases
 376   void op_init_mark();
 377   void op_final_mark();
 378   void op_final_evac();
 379   void op_init_updaterefs();
 380   void op_final_updaterefs();
 381   void op_init_traversal();
 382   void op_final_traversal();
 383   void op_full(GCCause::Cause cause);
 384   void op_degenerated(ShenandoahDegenPoint point);
 385   void op_degenerated_fail();
 386   void op_degenerated_futile();
 387 
 388   void op_reset();
 389   void op_mark();
 390   void op_preclean();
 391   void op_cleanup();
 392   void op_conc_evac();
 393   void op_stw_evac();
 394   void op_updaterefs();
 395   void op_traversal();
 396   void op_uncommit(double shrink_before);
 397 
 398   // Messages for GC trace event, they have to be immortal for
 399   // passing around the logging/tracing systems
 400   const char* init_mark_event_message() const;
 401   const char* final_mark_event_message() const;
 402   const char* conc_mark_event_message() const;
 403   const char* degen_event_message(ShenandoahDegenPoint point) const;
 404 
 405 // ---------- GC subsystems
 406 //
 407 private:
 408   ShenandoahControlThread*   _control_thread;
 409   ShenandoahCollectorPolicy* _shenandoah_policy;
 410   ShenandoahMode*            _gc_mode;
 411   ShenandoahHeuristics*      _heuristics;
 412   ShenandoahFreeSet*         _free_set;
 413   ShenandoahConcurrentMark*  _scm;
 414   ShenandoahTraversalGC*     _traversal_gc;
 415   ShenandoahMarkCompact*     _full_gc;
 416   ShenandoahPacer*           _pacer;
 417   ShenandoahVerifier*        _verifier;
 418 
 419   ShenandoahAllocTracker*    _alloc_tracker;
 420   ShenandoahPhaseTimings*    _phase_timings;
 421 
 422   ShenandoahControlThread*   control_thread()          { return _control_thread;    }
 423   ShenandoahMarkCompact*     full_gc()                 { return _full_gc;           }
 424 
 425 public:
 426   ShenandoahCollectorPolicy* shenandoah_policy() const { return _shenandoah_policy; }
 427   ShenandoahHeuristics*      heuristics()        const { return _heuristics;        }
 428   ShenandoahFreeSet*         free_set()          const { return _free_set;          }
 429   ShenandoahConcurrentMark*  concurrent_mark()         { return _scm;               }
 430   ShenandoahTraversalGC*     traversal_gc()      const { return _traversal_gc;      }
 431   bool                       is_traversal_mode() const { return _traversal_gc != NULL; }
 432   ShenandoahPacer*           pacer()             const { return _pacer;             }
 433 
 434   ShenandoahPhaseTimings*    phase_timings()     const { return _phase_timings;     }
 435   ShenandoahAllocTracker*    alloc_tracker()     const { return _alloc_tracker;     }
 436 
 437   ShenandoahVerifier*        verifier();
 438 
 439 // ---------- VM subsystem bindings
 440 //
 441 private:
 442   ShenandoahMonitoringSupport* _monitoring_support;
 443   ConcurrentGCTimer* _gc_timer;
 444 
 445 public:
 446   ShenandoahMonitoringSupport* monitoring_support() { return _monitoring_support; }
 447 
 448   GCTracer* tracer();
 449   GCTimer* gc_timer() const;
 450   CollectorPolicy* collector_policy() const;
 451 
 452 // ---------- Reference processing
 453 //
 454 private:
 455   ReferenceProcessor*  _ref_processor;
 456   ShenandoahSharedFlag _process_references;
 457 
 458   void ref_processing_init();
 459 
 460 public:
 461   ReferenceProcessor* ref_processor() { return _ref_processor;}
 462   void set_process_references(bool pr);
 463   bool process_references() const;
 464 
 465 // ---------- Class Unloading
 466 //
 467 private:
 468   ShenandoahSharedFlag _unload_classes;
 469 
 470 public:
 471   void set_unload_classes(bool uc);
 472   bool unload_classes() const;
 473 
 474   // Delete entries for dead interned string and clean up unreferenced symbols
 475   // in symbol table, possibly in parallel.
 476   void unload_classes_and_cleanup_tables(bool full_gc);
 477 
 478 // ---------- Generic interface hooks
 479 // Minor things that super-interface expects us to implement to play nice with
 480 // the rest of runtime. Some of the things here are not required to be implemented,
 481 // and can be stubbed out.
 482 //
 483 public:
 484   AdaptiveSizePolicy* size_policy() shenandoah_not_implemented_return(NULL);
 485   bool is_maximal_no_gc() const shenandoah_not_implemented_return(false);
 486 
 487   bool is_in(const void* p) const;
 488 
 489   // All objects can potentially move
 490   bool is_scavengable(const void* addr) { return true; }
 491 
 492   void collect(GCCause::Cause cause);
 493   void do_full_collection(bool clear_all_soft_refs);
 494 
 495   // Used for parsing heap during error printing
 496   HeapWord* block_start(const void* addr) const;
 497   size_t block_size(const HeapWord* addr) const;
 498   bool block_is_obj(const HeapWord* addr) const;
 499 
 500   // Used for native heap walkers: heap dumpers, mostly
 501   void object_iterate(ObjectClosure* cl);
 502   void safe_object_iterate(ObjectClosure* cl);
 503   void space_iterate(SpaceClosure* scl);
 504   void oop_iterate(ExtendedOopClosure* cl);
 505   Space* space_containing(const void* oop) const;
 506 
 507   // Used by RMI
 508   jlong millis_since_last_gc();
 509 
 510   bool can_elide_tlab_store_barriers() const                  { return true;    }
 511   oop new_store_pre_barrier(JavaThread* thread, oop new_obj)  { return new_obj; }
 512   bool can_elide_initializing_store_barrier(oop new_obj)      { return true;    }
 513   bool card_mark_must_follow_store() const                    { return false;   }
 514 
 515   bool is_in_partial_collection(const void* p) shenandoah_not_implemented_return(false);
 516   bool supports_heap_inspection() const { return true; }
 517 
 518   void gc_prologue(bool b);
 519   void gc_epilogue(bool b);
 520 
 521   void acquire_pending_refs_lock();
 522   void release_pending_refs_lock();
 523 
 524 // ---------- Code roots handling hooks
 525 //
 526 public:
 527   void register_nmethod(nmethod* nm);
 528   void unregister_nmethod(nmethod* nm);
 529 
 530 // ---------- Pinning hooks
 531 //
 532 public:
 533   // Shenandoah supports per-object (per-region) pinning
 534   bool supports_object_pinning() const { return true; }
 535 
 536   oop pin_object(JavaThread* thread, oop obj);
 537   void unpin_object(JavaThread* thread, oop obj);
 538 
 539   void sync_pinned_region_status();
 540   void assert_pinned_region_status() NOT_DEBUG_RETURN;
 541 
 542 // ---------- Allocation support
 543 //
 544 private:
 545   HeapWord* allocate_memory_under_lock(ShenandoahAllocRequest& request, bool& in_new_region);
 546   inline HeapWord* allocate_from_gclab(Thread* thread, size_t size);
 547   HeapWord* allocate_from_gclab_slow(Thread* thread, size_t size);
 548   HeapWord* allocate_new_gclab(size_t min_size, size_t word_size, size_t* actual_size);
 549 
 550 public:
 551   HeapWord* allocate_memory(ShenandoahAllocRequest& request);
 552   HeapWord* mem_allocate(size_t size, bool* what);
 553 
 554   void notify_mutator_alloc_words(size_t words, bool waste);
 555 
 556   // Shenandoah supports TLAB allocation
 557   bool supports_tlab_allocation() const { return true; }
 558 
 559   HeapWord* allocate_new_tlab(size_t word_size);
 560   size_t tlab_capacity(Thread *thr) const;
 561   size_t unsafe_max_tlab_alloc(Thread *thread) const;
 562   size_t max_tlab_size() const;
 563   size_t tlab_used(Thread* ignored) const;
 564 
 565   void resize_tlabs();
 566   void resize_all_tlabs();
 567 
 568   void accumulate_statistics_tlabs();
 569   void accumulate_statistics_all_gclabs();
 570 
 571   void make_parsable(bool retire_tlabs);
 572   void ensure_parsability(bool retire_tlabs);
 573 
 574 // ---------- Marking support
 575 //
 576 private:
 577   ShenandoahMarkingContext* _marking_context;
 578   MemRegion _bitmap_region;
 579   MemRegion _aux_bitmap_region;
 580   MarkBitMap _verification_bit_map;
 581   MarkBitMap _aux_bit_map;
 582 
 583   size_t _bitmap_size;
 584   size_t _bitmap_regions_per_slice;
 585   size_t _bitmap_bytes_per_slice;
 586 
 587   bool _bitmap_region_special;
 588   bool _aux_bitmap_region_special;
 589 
 590   // Used for buffering per-region liveness data.
 591   // Needed since ShenandoahHeapRegion uses atomics to update liveness.
 592   //
 593   // The array has max-workers elements, each of which is an array of
 594   // jushort * max_regions. The choice of jushort is not accidental:
 595   // there is a tradeoff between static/dynamic footprint that translates
 596   // into cache pressure (which is already high during marking), and
 597   // too many atomic updates. size_t/jint is too large, jbyte is too small.
 598   jushort** _liveness_cache;
 599 
 600 public:
 601   inline ShenandoahMarkingContext* complete_marking_context() const;
 602   inline ShenandoahMarkingContext* marking_context() const;
 603   inline void mark_complete_marking_context();
 604   inline void mark_incomplete_marking_context();
 605 
 606   template<class T>
 607   inline void marked_object_iterate(ShenandoahHeapRegion* region, T* cl);
 608 
 609   template<class T>
 610   inline void marked_object_iterate(ShenandoahHeapRegion* region, T* cl, HeapWord* limit);
 611 
 612   template<class T>
 613   inline void marked_object_oop_iterate(ShenandoahHeapRegion* region, T* cl, HeapWord* limit);
 614 
 615   void reset_mark_bitmap();
 616 
 617   // SATB barriers hooks
 618   inline bool requires_marking(const void* entry) const;
 619   void force_satb_flush_all_threads();
 620 
 621   // Support for bitmap uncommits
 622   bool commit_bitmap_slice(ShenandoahHeapRegion *r);
 623   bool uncommit_bitmap_slice(ShenandoahHeapRegion *r);
 624   bool is_bitmap_slice_committed(ShenandoahHeapRegion* r, bool skip_self = false);
 625 
 626   // Liveness caching support
 627   jushort* get_liveness_cache(uint worker_id);
 628   void flush_liveness_cache(uint worker_id);
 629 
 630 // ---------- Evacuation support
 631 //
 632 private:
 633   ShenandoahCollectionSet* _collection_set;
 634   ShenandoahEvacOOMHandler _oom_evac_handler;
 635 
 636   void evacuate_and_update_roots();
 637 
 638 public:
 639   static address in_cset_fast_test_addr();
 640 
 641   ShenandoahCollectionSet* collection_set() const { return _collection_set; }
 642 
 643   template <class T>
 644   inline bool in_collection_set(T obj) const;
 645 
 646   // Avoid accidentally calling the method above with ShenandoahHeapRegion*, which would be *wrong*.
 647   inline bool in_collection_set(ShenandoahHeapRegion* r) shenandoah_not_implemented_return(false);
 648 
 649   // Evacuates object src. Returns the evacuated object, either evacuated
 650   // by this thread, or by some other thread.
 651   inline oop  evacuate_object(oop src, Thread* thread);
 652 
 653   // Call before/after evacuation.
 654   void enter_evacuation();
 655   void leave_evacuation();
 656 
 657 // ---------- Helper functions
 658 //
 659 public:
 660   template <class T>
 661   inline oop evac_update_with_forwarded(T* p);
 662 
 663   template <class T>
 664   inline oop maybe_update_with_forwarded(T* p);
 665 
 666   template <class T>
 667   inline oop maybe_update_with_forwarded_not_null(T* p, oop obj);
 668 
 669   template <class T>
 670   inline oop update_with_forwarded_not_null(T* p, oop obj);
 671 
 672   static inline oop cas_oop(oop n, narrowOop* addr, oop c);
 673   static inline oop cas_oop(oop n, oop* addr, oop c);
 674 
 675   void trash_humongous_region_at(ShenandoahHeapRegion *r);
 676 
 677   void stop_concurrent_marking();
 678 
 679   void roots_iterate(OopClosure* cl);
 680 
 681 private:
 682   void trash_cset_regions();
 683   void update_heap_references(bool concurrent);
 684 
 685 // ---------- Testing helpers functions
 686 //
 687 private:
 688   ShenandoahSharedFlag _inject_alloc_failure;
 689 
 690   void try_inject_alloc_failure();
 691   bool should_inject_alloc_failure();
 692 };
 693 
 694 #endif // SHARE_VM_GC_SHENANDOAH_SHENANDOAHHEAP_HPP