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