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