1 /*
   2  * Copyright (c) 2013, 2017, Red Hat, Inc. and/or its affiliates.
   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_VM_GC_SHENANDOAH_SHENANDOAHHEAP_HPP
  25 #define SHARE_VM_GC_SHENANDOAH_SHENANDOAHHEAP_HPP
  26 
  27 #include "gc_implementation/shared/markBitMap.hpp"
  28 #include "gc_implementation/shenandoah/shenandoahHeapLock.hpp"
  29 #include "gc_implementation/shenandoah/shenandoahEvacOOMHandler.hpp"
  30 #include "gc_implementation/shenandoah/shenandoahSharedVariables.hpp"
  31 #include "gc_implementation/shenandoah/shenandoahWorkGroup.hpp"
  32 
  33 class ConcurrentGCTimer;
  34 
  35 class ShenandoahAllocTracker;
  36 class ShenandoahAsserts;
  37 class ShenandoahCollectionSet;
  38 class ShenandoahCollectorPolicy;
  39 class ShenandoahConcurrentMark;
  40 class ShenandoahControlThread;
  41 class ShenandoahGCSession;
  42 class ShenandoahFreeSet;
  43 class ShenandoahHeapRegion;
  44 class ShenandoahHeapRegionClosure;
  45 class ShenandoahMarkCompact;
  46 class ShenandoahMonitoringSupport;
  47 class ShenandoahHeuristics;
  48 class ShenandoahMarkingContext;
  49 class ShenandoahPhaseTimings;
  50 class ShenandoahPacer;
  51 class ShenandoahVerifier;
  52 class ShenandoahWorkGang;
  53 
  54 class ShenandoahRegionIterator : public StackObj {
  55 private:
  56   volatile jint _index;
  57   ShenandoahHeap* _heap;
  58 
  59   // No implicit copying: iterators should be passed by reference to capture the state
  60   ShenandoahRegionIterator(const ShenandoahRegionIterator& that);
  61   ShenandoahRegionIterator& operator=(const ShenandoahRegionIterator& o);
  62 
  63 public:
  64   ShenandoahRegionIterator();
  65   ShenandoahRegionIterator(ShenandoahHeap* heap);
  66 
  67   // Reset iterator to default state
  68   void reset();
  69 
  70   // Returns next region, or NULL if there are no more regions.
  71   // This is multi-thread-safe.
  72   inline ShenandoahHeapRegion* next();
  73 
  74   // This is *not* MT safe. However, in the absence of multithreaded access, it
  75   // can be used to determine if there is more work to do.
  76   bool has_next() const;
  77 };
  78 
  79 class ShenandoahHeapRegionClosure : public StackObj {
  80 public:
  81   // typically called on each region until it returns true;
  82   virtual bool heap_region_do(ShenandoahHeapRegion* r) = 0;
  83 };
  84 
  85 class ShenandoahUpdateRefsClosure: public OopClosure {
  86 private:
  87   ShenandoahHeap* _heap;
  88 
  89   template <class T>
  90   inline void do_oop_work(T* p);
  91 
  92 public:
  93   ShenandoahUpdateRefsClosure();
  94   inline void do_oop(oop* p);
  95   inline void do_oop(narrowOop* p);
  96 };
  97 
  98 #ifdef ASSERT
  99 class ShenandoahAssertToSpaceClosure : public OopClosure {
 100 private:
 101   template <class T>
 102   void do_oop_nv(T* p);
 103 public:
 104   void do_oop(narrowOop* p);
 105   void do_oop(oop* p);
 106 };
 107 #endif
 108 
 109 class ShenandoahAlwaysTrueClosure : public BoolObjectClosure {
 110 public:
 111   bool do_object_b(oop p) { return true; }
 112 };
 113 
 114 class ShenandoahForwardedIsAliveClosure: public BoolObjectClosure {
 115 private:
 116   ShenandoahMarkingContext* const _mark_context;
 117 public:
 118   ShenandoahForwardedIsAliveClosure();
 119   bool do_object_b(oop obj);
 120 };
 121 
 122 class ShenandoahIsAliveClosure: public BoolObjectClosure {
 123 private:
 124   ShenandoahMarkingContext* const _mark_context;
 125 public:
 126   ShenandoahIsAliveClosure();
 127   bool do_object_b(oop obj);
 128 };
 129 
 130 class VMStructs;
 131 
 132 // // A "ShenandoahHeap" is an implementation of a java heap for HotSpot.
 133 // // It uses a new pauseless GC algorithm based on Brooks pointers.
 134 // // Derived from G1
 135 
 136 // //
 137 // // CollectedHeap
 138 // //    SharedHeap
 139 // //      ShenandoahHeap
 140 
 141 class ShenandoahHeap : public SharedHeap {
 142   friend class ShenandoahAsserts;
 143   friend class VMStructs;
 144   friend class ShenandoahGCSession;
 145 public:
 146   // GC state describes the important parts of collector state, that may be
 147   // used to make barrier selection decisions in the native and generated code.
 148   // Multiple bits can be set at once.
 149   //
 150   // Important invariant: when GC state is zero, the heap is stable, and no barriers
 151   // are required.
 152   enum GCStateBitPos {
 153     // Heap has forwarded objects: need RB, ACMP, CAS barriers.
 154     HAS_FORWARDED_BITPOS   = 0,
 155 
 156     // Heap is under marking: needs SATB barriers.
 157     MARKING_BITPOS    = 1,
 158 
 159     // Heap is under evacuation: needs WB barriers. (Set together with UNSTABLE)
 160     EVACUATION_BITPOS = 2,
 161 
 162     // Heap is under updating: needs SVRB/SVWB barriers.
 163     UPDATEREFS_BITPOS = 3,
 164   };
 165 
 166   enum GCState {
 167     STABLE        = 0,
 168     HAS_FORWARDED = 1 << HAS_FORWARDED_BITPOS,
 169     MARKING       = 1 << MARKING_BITPOS,
 170     EVACUATION    = 1 << EVACUATION_BITPOS,
 171     UPDATEREFS    = 1 << UPDATEREFS_BITPOS,
 172   };
 173 
 174   enum ShenandoahDegenPoint {
 175     _degenerated_unset,
 176     _degenerated_outside_cycle,
 177     _degenerated_mark,
 178     _degenerated_evac,
 179     _degenerated_updaterefs,
 180     _DEGENERATED_LIMIT,
 181   };
 182 
 183   static const char* degen_point_to_string(ShenandoahDegenPoint point) {
 184     switch (point) {
 185       case _degenerated_unset:
 186         return "<UNSET>";
 187       case _degenerated_outside_cycle:
 188         return "Outside of Cycle";
 189       case _degenerated_mark:
 190         return "Mark";
 191       case _degenerated_evac:
 192         return "Evacuation";
 193       case _degenerated_updaterefs:
 194         return "Update Refs";
 195       default:
 196         ShouldNotReachHere();
 197         return "ERROR";
 198     }
 199   };
 200 
 201 private:
 202   ShenandoahSharedBitmap _gc_state;
 203   ShenandoahHeapLock _lock;
 204   ShenandoahCollectorPolicy* _shenandoah_policy;
 205   ShenandoahHeuristics* _heuristics;
 206   size_t _bitmap_size;
 207   size_t _bitmap_regions_per_slice;
 208   size_t _bitmap_bytes_per_slice;
 209   MemRegion _heap_region;
 210   MemRegion _bitmap0_region;
 211   MemRegion _bitmap1_region;
 212   MemRegion _aux_bitmap_region;
 213 
 214   ShenandoahHeapRegion** _regions;
 215   ShenandoahFreeSet* _free_set;
 216   ShenandoahCollectionSet* _collection_set;
 217 
 218   ShenandoahRegionIterator _update_refs_iterator;
 219 
 220   ShenandoahConcurrentMark* _scm;
 221   ShenandoahMarkCompact* _full_gc;
 222   ShenandoahVerifier*  _verifier;
 223   ShenandoahPacer*  _pacer;
 224 
 225 
 226 
 227   ShenandoahControlThread* _control_thread;
 228 
 229   ShenandoahMonitoringSupport* _monitoring_support;
 230 
 231   ShenandoahPhaseTimings*      _phase_timings;
 232   ShenandoahAllocTracker*      _alloc_tracker;
 233 
 234   size_t _num_regions;
 235   size_t _initial_size;
 236   uint _max_workers;
 237 
 238   ShenandoahWorkGang* _workers;
 239 
 240   volatile jlong _used;
 241   volatile size_t _committed;
 242 
 243   MarkBitMap _verification_bit_map;
 244   MarkBitMap _aux_bit_map;
 245 
 246   ShenandoahMarkingContext* _complete_marking_context;
 247   ShenandoahMarkingContext* _next_marking_context;
 248 
 249   volatile jlong _bytes_allocated_since_gc_start;
 250 
 251   ShenandoahSharedFlag _progress_last_gc;
 252 
 253   ShenandoahSharedFlag _degenerated_gc_in_progress;
 254   ShenandoahSharedFlag _full_gc_in_progress;
 255   ShenandoahSharedFlag _full_gc_move_in_progress;
 256 
 257   ShenandoahSharedFlag _inject_alloc_failure;
 258 
 259   ShenandoahSharedFlag _process_references;
 260   ShenandoahSharedFlag _unload_classes;
 261 
 262   ShenandoahSharedFlag _cancelled_gc;
 263 
 264   ReferenceProcessor* _ref_processor;
 265 
 266   ConcurrentGCTimer* _gc_timer;
 267 
 268   ShenandoahEvacOOMHandler _oom_evac_handler;
 269 
 270 #ifdef ASSERT
 271   int     _heap_expansion_count;
 272 #endif
 273 
 274 public:
 275   ShenandoahHeap(ShenandoahCollectorPolicy* policy);
 276 
 277   void initialize_heuristics();
 278 
 279   const char* name() const /* override */;
 280   HeapWord* allocate_new_tlab(size_t word_size) /* override */;
 281   void print_on(outputStream* st) const /* override */;
 282   void print_extended_on(outputStream *st) const /* override */;
 283 
 284   ShenandoahHeap::Name kind() const  /* override */{
 285     return CollectedHeap::ShenandoahHeap;
 286   }
 287 
 288   jint initialize() /* override */;
 289   void post_initialize() /* override */;
 290   size_t capacity() const /* override */;
 291   size_t used() const /* override */;
 292   size_t committed() const;
 293   bool is_maximal_no_gc() const /* override */;
 294   size_t max_capacity() const /* override */;
 295   size_t initial_capacity() const /* override */;
 296   bool is_in(const void* p) const /* override */;
 297   bool is_scavengable(const void* addr) /* override */;
 298   HeapWord* mem_allocate(size_t size, bool* what) /* override */;
 299   bool can_elide_tlab_store_barriers() const /* override */;
 300   oop new_store_pre_barrier(JavaThread* thread, oop new_obj) /* override */;
 301   bool can_elide_initializing_store_barrier(oop new_obj) /* override */;
 302   bool card_mark_must_follow_store() const /* override */;
 303   void collect(GCCause::Cause cause) /* override */;
 304   void do_full_collection(bool clear_all_soft_refs) /* override */;
 305   AdaptiveSizePolicy* size_policy() /* override */;
 306   CollectorPolicy* collector_policy() const /* override */;
 307   void ensure_parsability(bool retire_tlabs) /* override */;
 308   HeapWord* block_start(const void* addr) const /* override */;
 309   size_t block_size(const HeapWord* addr) const /* override */;
 310   bool block_is_obj(const HeapWord* addr) const /* override */;
 311   jlong millis_since_last_gc() /* override */;
 312   void prepare_for_verify() /* override */;
 313   void print_gc_threads_on(outputStream* st) const /* override */;
 314   void gc_threads_do(ThreadClosure* tcl) const /* override */;
 315   void print_tracing_info() const /* override */;
 316   void verify(bool silent, VerifyOption vo) /* override */;
 317   bool supports_tlab_allocation() const /* override */;
 318   size_t tlab_capacity(Thread *thr) const /* override */;
 319   void object_iterate(ObjectClosure* cl) /* override */;
 320   void safe_object_iterate(ObjectClosure* cl) /* override */;
 321   size_t unsafe_max_tlab_alloc(Thread *thread) const /* override */;
 322   size_t max_tlab_size() const /* override */;
 323   void resize_all_tlabs() /* override */;
 324   void accumulate_statistics_all_gclabs() /* override */;
 325   HeapWord* tlab_post_allocation_setup(HeapWord* obj) /* override */;
 326   uint oop_extra_words() /* override */;
 327   size_t tlab_used(Thread* ignored) const /* override */;
 328   void stop() /* override */;
 329   bool is_in_partial_collection(const void* p) /* override */;
 330   bool supports_heap_inspection() const /* override */;
 331 
 332   void space_iterate(SpaceClosure* scl) /* override */;
 333   void oop_iterate(ExtendedOopClosure* cl) /* override */;
 334 
 335   Space* space_containing(const void* oop) const;
 336   void gc_prologue(bool b);
 337   void gc_epilogue(bool b);
 338 
 339 #ifndef CC_INTERP
 340   void compile_prepare_oop(MacroAssembler* masm, Register obj) /* override */;
 341 #endif
 342 
 343   void register_nmethod(nmethod* nm);
 344   void unregister_nmethod(nmethod* nm);
 345 
 346   /* override: object pinning support */
 347   bool supports_object_pinning() const { return true; }
 348   oop pin_object(JavaThread* thread, oop obj);
 349   void unpin_object(JavaThread* thread, oop obj);
 350 
 351   static ShenandoahHeap* heap();
 352   static ShenandoahHeap* heap_no_check();
 353   static size_t conservative_max_heap_alignment();
 354   static address in_cset_fast_test_addr();
 355   static address cancelled_gc_addr();
 356   static address gc_state_addr();
 357 
 358   ShenandoahCollectorPolicy *shenandoahPolicy() const { return _shenandoah_policy; }
 359   ShenandoahHeuristics*     heuristics()        const { return _heuristics; }
 360   ShenandoahPhaseTimings*   phase_timings()     const { return _phase_timings; }
 361   ShenandoahAllocTracker*   alloc_tracker()     const { return _alloc_tracker; }
 362 
 363   inline ShenandoahHeapRegion* const heap_region_containing(const void* addr) const;
 364   inline size_t heap_region_index_containing(const void* addr) const;
 365   inline bool requires_marking(const void* entry) const;
 366 
 367   template <class T>
 368   inline oop maybe_update_with_forwarded(T* p);
 369 
 370   template <class T>
 371   inline oop maybe_update_with_forwarded_not_null(T* p, oop obj);
 372 
 373   template <class T>
 374   inline oop update_with_forwarded_not_null(T* p, oop obj);
 375 
 376   void trash_cset_regions();
 377 
 378   void stop_concurrent_marking();
 379 
 380   void prepare_for_concurrent_evacuation();
 381   void evacuate_and_update_roots();
 382 
 383   void update_heap_references(bool concurrent);
 384 
 385   void roots_iterate(OopClosure* cl);
 386 
 387 private:
 388   void set_gc_state_mask(uint mask, bool value);
 389 
 390 public:
 391   void set_concurrent_mark_in_progress(bool in_progress);
 392   void set_evacuation_in_progress(bool in_progress);
 393   void set_update_refs_in_progress(bool in_progress);
 394   void set_degenerated_gc_in_progress(bool in_progress);
 395   void set_full_gc_in_progress(bool in_progress);
 396   void set_full_gc_move_in_progress(bool in_progress);
 397   void set_has_forwarded_objects(bool cond);
 398 
 399   char gc_state();
 400 
 401   void set_process_references(bool pr);
 402   void set_unload_classes(bool uc);
 403 
 404   inline bool is_stable() const;
 405   inline bool is_idle() const;
 406   inline bool is_concurrent_mark_in_progress() const;
 407   inline bool is_update_refs_in_progress() const;
 408   inline bool is_evacuation_in_progress() const;
 409   inline bool is_degenerated_gc_in_progress() const;
 410   inline bool is_full_gc_in_progress() const;
 411   inline bool is_full_gc_move_in_progress() const;
 412   inline bool has_forwarded_objects() const;
 413   inline bool is_gc_in_progress_mask(uint mask) const;
 414 
 415   bool process_references() const;
 416   bool unload_classes() const;
 417 
 418   void force_satb_flush_all_threads();
 419 
 420   bool last_gc_made_progress() const;
 421 
 422   inline bool region_in_collection_set(size_t region_index) const;
 423 
 424   void acquire_pending_refs_lock();
 425   void release_pending_refs_lock();
 426 
 427   // Mainly there to avoid accidentally calling the templated
 428   // method below with ShenandoahHeapRegion* which would be *wrong*.
 429   inline bool in_collection_set(ShenandoahHeapRegion* r) const;
 430 
 431   template <class T>
 432   inline bool in_collection_set(T obj) const;
 433 
 434   // Evacuates object src. Returns the evacuated object if this thread
 435   // succeeded, otherwise rolls back the evacuation and returns the
 436   // evacuated object by the competing thread. 'succeeded' is an out
 437   // param and set to true if this thread succeeded, otherwise to false.
 438   inline oop  evacuate_object(oop src, Thread* thread, bool& evacuated);
 439   inline bool cancelled_gc() const;
 440   inline bool try_cancel_gc();
 441   inline void clear_cancelled_gc();
 442 
 443   inline ShenandoahHeapRegion* const get_region(size_t region_idx) const;
 444   void heap_region_iterate(ShenandoahHeapRegionClosure& cl) const;
 445 
 446   ShenandoahFreeSet* free_set()             const { return _free_set; }
 447   ShenandoahCollectionSet* collection_set() const { return _collection_set; }
 448 
 449   void increase_used(size_t bytes);
 450   void decrease_used(size_t bytes);
 451 
 452   void set_used(size_t bytes);
 453 
 454   void increase_committed(size_t bytes);
 455   void decrease_committed(size_t bytes);
 456 
 457   void increase_allocated(size_t bytes);
 458 
 459   void notify_mutator_alloc_words(size_t words, bool waste);
 460 
 461   void reset_next_mark_bitmap();
 462 
 463   inline ShenandoahMarkingContext* complete_marking_context() const {
 464     return _complete_marking_context;
 465   }
 466 
 467   inline ShenandoahMarkingContext* next_marking_context() const {
 468     return _next_marking_context;
 469   }
 470 
 471   bool commit_bitmap_slice(ShenandoahHeapRegion *r);
 472   bool uncommit_bitmap_slice(ShenandoahHeapRegion *r);
 473   bool is_bitmap_slice_committed(ShenandoahHeapRegion* r, bool skip_self = false);
 474 
 475   void print_heap_regions_on(outputStream* st) const;
 476 
 477   size_t bytes_allocated_since_gc_start();
 478   void reset_bytes_allocated_since_gc_start();
 479 
 480   void trash_humongous_region_at(ShenandoahHeapRegion *r);
 481 
 482   ShenandoahMonitoringSupport* monitoring_support();
 483   ShenandoahConcurrentMark* concurrentMark() { return _scm; }
 484   ShenandoahMarkCompact* full_gc() { return _full_gc; }
 485   ShenandoahVerifier* verifier();
 486   ShenandoahPacer* pacer() const;
 487 
 488   ReferenceProcessor* ref_processor() { return _ref_processor;}
 489 
 490   ShenandoahWorkGang* workers() const { return _workers;}
 491 
 492   uint max_workers();
 493 
 494   void assert_gc_workers(uint nworker) PRODUCT_RETURN;
 495 
 496   ShenandoahHeapRegion* next_compaction_region(const ShenandoahHeapRegion* r);
 497 
 498   void heap_region_iterate(ShenandoahHeapRegionClosure* blk, bool skip_cset_regions = false, bool skip_humongous_continuation = false) const;
 499 
 500   // Delete entries for dead interned string and clean up unreferenced symbols
 501   // in symbol table, possibly in parallel.
 502   void unload_classes_and_cleanup_tables(bool full_gc);
 503 
 504   inline size_t num_regions() const { return _num_regions; }
 505 
 506   // Call before starting evacuation.
 507   void enter_evacuation();
 508   // Call after finished with evacuation.
 509   void leave_evacuation();
 510 
 511 private:
 512   template<class T>
 513   inline void marked_object_iterate(ShenandoahHeapRegion* region, T* cl, HeapWord* limit);
 514 
 515   template<class T>
 516   inline void marked_object_oop_iterate(ShenandoahHeapRegion* region, T* cl, HeapWord* limit);
 517 
 518 public:
 519   template<class T>
 520   inline void marked_object_iterate(ShenandoahHeapRegion* region, T* cl);
 521 
 522   template<class T>
 523   inline void marked_object_safe_iterate(ShenandoahHeapRegion* region, T* cl);
 524 
 525   template<class T>
 526   inline void marked_object_oop_iterate(ShenandoahHeapRegion* region, T* cl);
 527 
 528   template<class T>
 529   inline void marked_object_oop_safe_iterate(ShenandoahHeapRegion* region, T* cl);
 530 
 531   GCTimer* gc_timer() const;
 532   GCTracer* tracer();
 533 
 534   void swap_mark_contexts();
 535 
 536   void cancel_gc(GCCause::Cause cause);
 537 
 538   ShenandoahHeapLock* lock() { return &_lock; }
 539   void assert_heaplock_owned_by_current_thread() PRODUCT_RETURN;
 540   void assert_heaplock_not_owned_by_current_thread() PRODUCT_RETURN;
 541   void assert_heaplock_or_safepoint() PRODUCT_RETURN;
 542 
 543 public:
 544   typedef enum {
 545     _alloc_shared,      // Allocate common, outside of TLAB
 546     _alloc_shared_gc,   // Allocate common, outside of GCLAB
 547     _alloc_tlab,        // Allocate TLAB
 548     _alloc_gclab,       // Allocate GCLAB
 549     _ALLOC_LIMIT,
 550   } AllocType;
 551 
 552   static const char* alloc_type_to_string(AllocType type) {
 553     switch (type) {
 554       case _alloc_shared:
 555         return "Shared";
 556       case _alloc_shared_gc:
 557         return "Shared GC";
 558       case _alloc_tlab:
 559         return "TLAB";
 560       case _alloc_gclab:
 561         return "GCLAB";
 562       default:
 563         ShouldNotReachHere();
 564         return "";
 565     }
 566   }
 567 
 568   class ShenandoahAllocationRequest : StackObj {
 569   private:
 570     size_t _min_size;
 571     size_t _requested_size;
 572     size_t _actual_size;
 573     AllocType _alloc_type;
 574 #ifdef ASSERT
 575     bool _actual_size_set;
 576 #endif
 577 
 578     ShenandoahAllocationRequest(size_t _min_size, size_t _requested_size, AllocType _alloc_type) :
 579             _min_size(_min_size), _requested_size(_requested_size),
 580             _actual_size(0), _alloc_type(_alloc_type)
 581 #ifdef ASSERT
 582             , _actual_size_set(false)
 583 #endif
 584     {}
 585 
 586   public:
 587     static inline ShenandoahAllocationRequest for_tlab(size_t requested_size) {
 588       return ShenandoahAllocationRequest(requested_size, requested_size, ShenandoahHeap::_alloc_tlab);
 589     }
 590 
 591     static inline ShenandoahAllocationRequest for_gclab(size_t min_size, size_t requested_size) {
 592       return ShenandoahAllocationRequest(min_size, requested_size, ShenandoahHeap::_alloc_gclab);
 593     }
 594 
 595     static inline ShenandoahAllocationRequest for_shared_gc(size_t requested_size) {
 596       return ShenandoahAllocationRequest(0, requested_size, ShenandoahHeap::_alloc_shared_gc);
 597     }
 598 
 599     static inline ShenandoahAllocationRequest for_shared(size_t requested_size) {
 600       return ShenandoahAllocationRequest(0, requested_size, ShenandoahHeap::_alloc_shared);
 601     }
 602 
 603     inline size_t size() {
 604       return _requested_size;
 605     }
 606 
 607     inline AllocType type() {
 608       return _alloc_type;
 609     }
 610 
 611     inline size_t min_size() {
 612       assert (is_lab_alloc(), "Only access for LAB allocs");
 613       return _min_size;
 614     }
 615 
 616     inline size_t actual_size() {
 617       assert (_actual_size_set, "Should be set");
 618       return _actual_size;
 619     }
 620 
 621     inline void set_actual_size(size_t v) {
 622 #ifdef ASSERT
 623       assert (!_actual_size_set, "Should not be set");
 624       _actual_size_set = true;
 625 #endif
 626       _actual_size = v;
 627     }
 628 
 629     inline bool is_mutator_alloc() {
 630       switch (_alloc_type) {
 631         case _alloc_tlab:
 632         case _alloc_shared:
 633           return true;
 634         case _alloc_gclab:
 635         case _alloc_shared_gc:
 636           return false;
 637         default:
 638           ShouldNotReachHere();
 639           return false;
 640       }
 641     }
 642 
 643     inline bool is_gc_alloc() {
 644       switch (_alloc_type) {
 645         case _alloc_tlab:
 646         case _alloc_shared:
 647           return false;
 648         case _alloc_gclab:
 649         case _alloc_shared_gc:
 650           return true;
 651         default:
 652           ShouldNotReachHere();
 653           return false;
 654       }
 655     }
 656 
 657     inline bool is_lab_alloc() {
 658       switch (_alloc_type) {
 659         case _alloc_tlab:
 660         case _alloc_gclab:
 661           return true;
 662         case _alloc_shared:
 663         case _alloc_shared_gc:
 664           return false;
 665         default:
 666           ShouldNotReachHere();
 667           return false;
 668       }
 669     }
 670   };
 671 
 672 
 673 private:
 674   HeapWord* allocate_memory_under_lock(ShenandoahAllocationRequest& request, bool& in_new_region);
 675   HeapWord* allocate_memory(ShenandoahAllocationRequest& request);
 676 
 677   // Shenandoah functionality.
 678   inline HeapWord* allocate_from_gclab(Thread* thread, size_t size);
 679   HeapWord* allocate_from_gclab_slow(Thread* thread, size_t size);
 680   HeapWord* allocate_new_gclab(size_t min_size, size_t word_size, size_t* actual_size);
 681 
 682   template<class T>
 683   inline void do_object_marked_complete(T* cl, oop obj);
 684 
 685   ShenandoahControlThread* control_thread() { return _control_thread; }
 686 
 687   inline oop atomic_compare_exchange_oop(oop n, narrowOop* addr, oop c);
 688   inline oop atomic_compare_exchange_oop(oop n, oop* addr, oop c);
 689 
 690   void ref_processing_init();
 691 
 692 public:
 693   void make_parsable(bool retire_tlabs);
 694   void accumulate_statistics_tlabs();
 695   void resize_tlabs();
 696 
 697 public:
 698   // Entry points to STW GC operations, these cause a related safepoint, that then
 699   // call the entry method below
 700   void vmop_entry_init_mark();
 701   void vmop_entry_final_mark();
 702   void vmop_entry_final_evac();
 703   void vmop_entry_init_updaterefs();
 704   void vmop_entry_final_updaterefs();
 705   void vmop_entry_full(GCCause::Cause cause);
 706   void vmop_degenerated(ShenandoahDegenPoint point);
 707 
 708   // Entry methods to normally STW GC operations. These set up logging, monitoring
 709   // and workers for net VM operation
 710   void entry_init_mark();
 711   void entry_final_mark();
 712   void entry_final_evac();
 713   void entry_init_updaterefs();
 714   void entry_final_updaterefs();
 715   void entry_full(GCCause::Cause cause);
 716   void entry_degenerated(int point);
 717 
 718   // Entry methods to normally concurrent GC operations. These set up logging, monitoring
 719   // for concurrent operation.
 720   void entry_mark();
 721   void entry_preclean();
 722   void entry_cleanup();
 723   void entry_cleanup_bitmaps();
 724   void entry_evac();
 725   void entry_updaterefs();
 726   void entry_uncommit(double shrink_before);
 727 
 728 private:
 729   // Actual work for the phases
 730   void op_init_mark();
 731   void op_final_mark();
 732   void op_final_evac();
 733   void op_init_updaterefs();
 734   void op_final_updaterefs();
 735   void op_full(GCCause::Cause cause);
 736   void op_degenerated(ShenandoahDegenPoint point);
 737   void op_degenerated_fail();
 738   void op_degenerated_futile();
 739 
 740   void op_mark();
 741   void op_preclean();
 742   void op_cleanup();
 743   void op_evac();
 744   void op_updaterefs();
 745   void op_cleanup_bitmaps();
 746   void op_uncommit(double shrink_before);
 747 
 748   // Messages for GC trace event, they have to be immortal for
 749   // passing around the logging/tracing systems
 750   const char* init_mark_event_message() const;
 751   const char* final_mark_event_message() const;
 752   const char* conc_mark_event_message() const;
 753   const char* degen_event_message(ShenandoahDegenPoint point) const;
 754 
 755 private:
 756   void try_inject_alloc_failure();
 757   bool should_inject_alloc_failure();
 758 };
 759 
 760 class ShenandoahIsAliveSelector : public StackObj {
 761 private:
 762   ShenandoahIsAliveClosure _alive_cl;
 763   ShenandoahForwardedIsAliveClosure _fwd_alive_cl;
 764 public:
 765   BoolObjectClosure* is_alive_closure();
 766 };
 767 
 768 
 769 #endif // SHARE_VM_GC_SHENANDOAH_SHENANDOAHHEAP_HPP