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