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