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