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