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