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