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