1 /*
  2  * Copyright (c) 2013, 2021, 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/mode/shenandoahGenerationalMode.hpp"
 32 #include "gc/shenandoah/shenandoahAsserts.hpp"
 33 #include "gc/shenandoah/shenandoahAllocRequest.hpp"
 34 #include "gc/shenandoah/shenandoahLock.hpp"
 35 #include "gc/shenandoah/shenandoahEvacOOMHandler.hpp"
 36 #include "gc/shenandoah/shenandoahPadding.hpp"
 37 #include "gc/shenandoah/shenandoahSharedVariables.hpp"
 38 #include "gc/shenandoah/shenandoahUnload.hpp"
 39 #include "gc/shenandoah/shenandoahScanRemembered.hpp"
 40 #include "memory/metaspace.hpp"
 41 #include "services/memoryManager.hpp"
 42 #include "utilities/globalDefinitions.hpp"
 43 #include "utilities/stack.hpp"
 44 
 45 class ConcurrentGCTimer;
 46 class ObjectIterateScanRootClosure;
 47 class PLAB;
 48 class ShenandoahCollectorPolicy;
 49 class ShenandoahControlThread;
 50 class ShenandoahRegulatorThread;
 51 class ShenandoahGCSession;
 52 class ShenandoahGCStateResetter;
 53 class ShenandoahGeneration;
 54 class ShenandoahYoungGeneration;
 55 class ShenandoahHeuristics;
 56 class ShenandoahOldHeuristics;
 57 class ShenandoahMarkingContext;
 58 class ShenandoahPhaseTimings;
 59 class ShenandoahHeap;
 60 class ShenandoahHeapRegion;
 61 class ShenandoahHeapRegionClosure;
 62 class ShenandoahCollectionSet;
 63 class ShenandoahFreeSet;
 64 class ShenandoahConcurrentMark;
 65 class ShenandoahFullGC;
 66 class ShenandoahMonitoringSupport;
 67 class ShenandoahPacer;
 68 class ShenandoahReferenceProcessor;
 69 class ShenandoahVerifier;
 70 class ShenandoahWorkGang;
 71 class VMStructs;
 72 
 73 // Used for buffering per-region liveness data.
 74 // Needed since ShenandoahHeapRegion uses atomics to update liveness.
 75 // The ShenandoahHeap array has max-workers elements, each of which is an array of
 76 // uint16_t * max_regions. The choice of uint16_t is not accidental:
 77 // there is a tradeoff between static/dynamic footprint that translates
 78 // into cache pressure (which is already high during marking), and
 79 // too many atomic updates. uint32_t is too large, uint8_t is too small.
 80 typedef uint16_t ShenandoahLiveData;
 81 #define SHENANDOAH_LIVEDATA_MAX ((ShenandoahLiveData)-1)
 82 
 83 class ShenandoahRegionIterator : public StackObj {
 84 private:
 85   ShenandoahHeap* _heap;
 86 
 87   shenandoah_padding(0);
 88   volatile size_t _index;
 89   shenandoah_padding(1);
 90 
 91   // No implicit copying: iterators should be passed by reference to capture the state
 92   NONCOPYABLE(ShenandoahRegionIterator);
 93 
 94 public:
 95   ShenandoahRegionIterator();
 96   ShenandoahRegionIterator(ShenandoahHeap* heap);
 97 
 98   // Reset iterator to default state
 99   void reset();
100 
101   // Returns next region, or NULL if there are no more regions.
102   // This is multi-thread-safe.
103   inline ShenandoahHeapRegion* next();
104 
105   // This is *not* MT safe. However, in the absence of multithreaded access, it
106   // can be used to determine if there is more work to do.
107   bool has_next() const;
108 };
109 
110 class ShenandoahHeapRegionClosure : public StackObj {
111 public:
112   virtual void heap_region_do(ShenandoahHeapRegion* r) = 0;
113   virtual bool is_thread_safe() { return false; }
114 };
115 
116 template<GenerationMode GENERATION>
117 class ShenandoahGenerationRegionClosure : public ShenandoahHeapRegionClosure {
118  public:
119   explicit ShenandoahGenerationRegionClosure(ShenandoahHeapRegionClosure* cl) : _cl(cl) {}
120   void heap_region_do(ShenandoahHeapRegion* r);
121   virtual bool is_thread_safe() { return _cl->is_thread_safe(); }
122  private:
123   ShenandoahHeapRegionClosure* _cl;
124 };
125 
126 typedef ShenandoahLock    ShenandoahHeapLock;
127 typedef ShenandoahLocker  ShenandoahHeapLocker;
128 typedef Stack<oop, mtGC>  ShenandoahScanObjectStack;
129 
130 // Shenandoah GC is low-pause concurrent GC that uses Brooks forwarding pointers
131 // to encode forwarding data. See BrooksPointer for details on forwarding data encoding.
132 // See ShenandoahControlThread for GC cycle structure.
133 //
134 class ShenandoahHeap : public CollectedHeap {
135   friend class ShenandoahAsserts;
136   friend class VMStructs;
137   friend class ShenandoahGCSession;
138   friend class ShenandoahGCStateResetter;
139   friend class ShenandoahParallelObjectIterator;
140   friend class ShenandoahSafepoint;
141   // Supported GC
142   friend class ShenandoahConcurrentGC;
143   friend class ShenandoahOldGC;
144   friend class ShenandoahDegenGC;
145   friend class ShenandoahFullGC;
146   friend class ShenandoahUnload;
147 
148 // ---------- Locks that guard important data structures in Heap
149 //
150 private:
151   ShenandoahHeapLock _lock;
152   ShenandoahGeneration* _gc_generation;
153   bool _mixed_evac;             // true iff most recent evac included at least one old-gen HeapRegion
154   bool _prep_for_mixed_evac_in_progress; // true iff we are concurrently coalescing and filling old-gen HeapRegions
155 
156 public:
157   ShenandoahHeapLock* lock() {
158     return &_lock;
159   }
160 
161   ShenandoahGeneration* active_generation() const {
162     // last or latest generation might be a better name here.
163     return _gc_generation;
164   }
165 
166   void set_gc_generation(ShenandoahGeneration* generation) {
167     _gc_generation = generation;
168   }
169 
170   void set_mixed_evac(bool mixed_evac) {
171     _mixed_evac = mixed_evac;
172   }
173 
174   ShenandoahOldHeuristics* old_heuristics();
175 
176   bool doing_mixed_evacuations();
177 
178   bool is_gc_generation_young() const;
179 
180 // ---------- Initialization, termination, identification, printing routines
181 //
182 public:
183   static ShenandoahHeap* heap();
184 
185   const char* name()          const { return "Shenandoah"; }
186   ShenandoahHeap::Name kind() const { return CollectedHeap::Shenandoah; }
187 
188   ShenandoahHeap(ShenandoahCollectorPolicy* policy);
189   jint initialize();
190   void post_initialize();
191   void initialize_mode();
192   void initialize_heuristics();
193   void initialize_generations();
194 
195   void initialize_serviceability();
196 
197   void print_on(outputStream* st)              const;
198   void print_extended_on(outputStream *st)     const;
199   void print_tracing_info()                    const;
200   void print_heap_regions_on(outputStream* st) const;
201 
202   void stop();
203 
204   void prepare_for_verify();
205   void verify(VerifyOption vo);
206   void verify_rem_set_at_mark();
207   void verify_rem_set_at_update_ref();
208   void verify_rem_set_after_full_gc();
209 
210 // WhiteBox testing support.
211   bool supports_concurrent_gc_breakpoints() const {
212     return true;
213   }
214 
215 // ---------- Heap counters and metrics
216 //
217 private:
218            size_t _initial_size;
219            size_t _minimum_size;
220   volatile size_t _soft_max_size;
221   shenandoah_padding(0);
222   volatile size_t _used;
223   volatile size_t _committed;
224   shenandoah_padding(1);
225 
226   static size_t young_generation_capacity(size_t total_capacity);
227   void help_verify_region_rem_set(ShenandoahHeapRegion* r, ShenandoahMarkingContext* ctx,
228                                   HeapWord* from, HeapWord* top, HeapWord* update_watermark, const char* message);
229 
230 public:
231   void increase_used(size_t bytes);
232   void decrease_used(size_t bytes);
233   void set_used(size_t bytes);
234 
235   void increase_committed(size_t bytes);
236   void decrease_committed(size_t bytes);
237 
238   void reset_bytes_allocated_since_gc_start();
239 
240   size_t min_capacity()      const;
241   size_t max_capacity()      const;
242   size_t soft_max_capacity() const;
243   size_t initial_capacity()  const;
244   size_t capacity()          const;
245   size_t used()              const;
246   size_t committed()         const;
247 
248   void set_soft_max_capacity(size_t v);
249 
250 // ---------- Workers handling
251 //
252 private:
253   uint _max_workers;
254   ShenandoahWorkGang* _workers;
255   ShenandoahWorkGang* _safepoint_workers;
256 
257 public:
258   uint max_workers();
259   void assert_gc_workers(uint nworker) NOT_DEBUG_RETURN;
260 
261   WorkGang* workers() const;
262   WorkGang* safepoint_workers();
263 
264   void gc_threads_do(ThreadClosure* tcl) const;
265 
266 // ---------- Heap regions handling machinery
267 //
268 private:
269   MemRegion _heap_region;
270   bool      _heap_region_special;
271   size_t    _num_regions;
272   ShenandoahHeapRegion** _regions;
273   ShenandoahRegionIterator _update_refs_iterator;
274 
275 public:
276 
277   inline HeapWord* base() const { return _heap_region.start(); }
278 
279   inline size_t num_regions() const { return _num_regions; }
280   inline bool is_heap_region_special() { return _heap_region_special; }
281 
282   inline ShenandoahHeapRegion* const heap_region_containing(const void* addr) const;
283   inline size_t heap_region_index_containing(const void* addr) const;
284 
285   inline ShenandoahHeapRegion* const get_region(size_t region_idx) const;
286 
287   void heap_region_iterate(ShenandoahHeapRegionClosure* blk) const;
288   void parallel_heap_region_iterate(ShenandoahHeapRegionClosure* blk) const;
289 
290 // ---------- GC state machinery
291 //
292 // GC state describes the important parts of collector state, that may be
293 // used to make barrier selection decisions in the native and generated code.
294 // Multiple bits can be set at once.
295 //
296 // Important invariant: when GC state is zero, the heap is stable, and no barriers
297 // are required.
298 //
299 public:
300   enum GCStateBitPos {
301     // Heap has forwarded objects: needs LRB barriers.
302     HAS_FORWARDED_BITPOS   = 0,
303 
304     // Young regions are under marking: needs SATB barriers.
305     YOUNG_MARKING_BITPOS    = 1,
306 
307     // Heap is under evacuation: needs LRB barriers. (Set together with HAS_FORWARDED)
308     EVACUATION_BITPOS = 2,
309 
310     // Heap is under updating: needs no additional barriers.
311     UPDATEREFS_BITPOS = 3,
312 
313     // Heap is under weak-reference/roots processing: needs weak-LRB barriers.
314     WEAK_ROOTS_BITPOS  = 4,
315 
316     // Old regions are under marking, still need SATB barriers.
317     OLD_MARKING_BITPOS = 5
318   };
319 
320   enum GCState {
321     STABLE        = 0,
322     HAS_FORWARDED = 1 << HAS_FORWARDED_BITPOS,
323     YOUNG_MARKING = 1 << YOUNG_MARKING_BITPOS,
324     EVACUATION    = 1 << EVACUATION_BITPOS,
325     UPDATEREFS    = 1 << UPDATEREFS_BITPOS,
326     WEAK_ROOTS    = 1 << WEAK_ROOTS_BITPOS,
327     OLD_MARKING   = 1 << OLD_MARKING_BITPOS
328   };
329 
330 private:
331   ShenandoahSharedBitmap _gc_state;
332   ShenandoahSharedFlag   _degenerated_gc_in_progress;
333   ShenandoahSharedFlag   _full_gc_in_progress;
334   ShenandoahSharedFlag   _full_gc_move_in_progress;
335   ShenandoahSharedFlag   _progress_last_gc;
336   ShenandoahSharedFlag   _concurrent_strong_root_in_progress;
337 
338   void set_gc_state_all_threads(char state);
339   void set_gc_state_mask(uint mask, bool value);
340 
341 public:
342   char gc_state() const;
343   static address gc_state_addr();
344 
345   void set_concurrent_young_mark_in_progress(bool in_progress);
346   void set_concurrent_old_mark_in_progress(bool in_progress);
347   void set_evacuation_in_progress(bool in_progress);
348   void set_update_refs_in_progress(bool in_progress);
349   void set_degenerated_gc_in_progress(bool in_progress);
350   void set_full_gc_in_progress(bool in_progress);
351   void set_full_gc_move_in_progress(bool in_progress);
352   void set_has_forwarded_objects(bool cond);
353   void set_concurrent_strong_root_in_progress(bool cond);
354   void set_concurrent_weak_root_in_progress(bool cond);
355   void set_concurrent_prep_for_mixed_evacuation_in_progress(bool cond);
356   void set_aging_cycle(bool cond);
357 
358   inline bool is_stable() const;
359   inline bool is_idle() const;
360   inline bool is_concurrent_mark_in_progress() const;
361   inline bool is_concurrent_young_mark_in_progress() const;
362   inline bool is_concurrent_old_mark_in_progress() const;
363   inline bool is_update_refs_in_progress() const;
364   inline bool is_evacuation_in_progress() const;
365   inline bool is_degenerated_gc_in_progress() const;
366   inline bool is_full_gc_in_progress() const;
367   inline bool is_full_gc_move_in_progress() const;
368   inline bool has_forwarded_objects() const;
369   inline bool is_gc_in_progress_mask(uint mask) const;
370   inline bool is_stw_gc_in_progress() const;
371   inline bool is_concurrent_strong_root_in_progress() const;
372   inline bool is_concurrent_weak_root_in_progress() const;
373   bool is_concurrent_prep_for_mixed_evacuation_in_progress();
374   inline bool is_aging_cycle() const;
375 
376 private:
377   void manage_satb_barrier(bool active);
378 
379   enum CancelState {
380     // Normal state. GC has not been cancelled and is open for cancellation.
381     // Worker threads can suspend for safepoint.
382     CANCELLABLE,
383 
384     // GC has been cancelled. Worker threads can not suspend for
385     // safepoint but must finish their work as soon as possible.
386     CANCELLED,
387 
388     // GC has not been cancelled and must not be cancelled. At least
389     // one worker thread checks for pending safepoint and may suspend
390     // if a safepoint is pending.
391     NOT_CANCELLED
392   };
393 
394   double _cancel_requested_time;
395   ShenandoahSharedEnumFlag<CancelState> _cancelled_gc;
396 
397   // Returns true if cancel request was successfully communicated.
398   // Returns false if some other thread already communicated cancel
399   // request.  A true return value does not mean GC has been
400   // cancelled, only that the process of cancelling GC has begun.
401   bool try_cancel_gc();
402 
403 public:
404   inline bool cancelled_gc() const;
405   inline bool check_cancelled_gc_and_yield(bool sts_active = true);
406 
407   inline void clear_cancelled_gc(bool clear_oom_handler = true);
408 
409   void cancel_concurrent_mark();
410   void cancel_gc(GCCause::Cause cause);
411 
412 public:
413   // Elastic heap support
414   void entry_uncommit(double shrink_before, size_t shrink_until);
415   void op_uncommit(double shrink_before, size_t shrink_until);
416 
417 private:
418   // GC support
419   // Evacuation
420   void evacuate_collection_set(bool concurrent);
421   // Concurrent root processing
422   void prepare_concurrent_roots();
423   void finish_concurrent_roots();
424   // Concurrent class unloading support
425   void do_class_unloading();
426   // Reference updating
427   void prepare_update_heap_references(bool concurrent);
428   void update_heap_references(bool concurrent);
429   // Final update region states
430   void update_heap_region_states(bool concurrent);
431   void rebuild_free_set(bool concurrent);
432 
433   void rendezvous_threads();
434   void recycle_trash();
435 public:
436   void notify_gc_progress()    { _progress_last_gc.set();   }
437   void notify_gc_no_progress() { _progress_last_gc.unset(); }
438 
439 //
440 // Mark support
441 private:
442   ShenandoahYoungGeneration* _young_generation;
443   ShenandoahGeneration*      _global_generation;
444   ShenandoahGeneration*      _old_generation;
445 
446   ShenandoahControlThread*   _control_thread;
447   ShenandoahRegulatorThread* _regulator_thread;
448   ShenandoahCollectorPolicy* _shenandoah_policy;
449   ShenandoahMode*            _gc_mode;
450   ShenandoahFreeSet*         _free_set;
451   ShenandoahPacer*           _pacer;
452   ShenandoahVerifier*        _verifier;
453 
454   ShenandoahPhaseTimings*    _phase_timings;
455 
456   ShenandoahControlThread*   control_thread()          { return _control_thread;    }
457   ShenandoahRegulatorThread* regulator_thread()        { return _regulator_thread;  }
458 
459 public:
460   ShenandoahYoungGeneration* young_generation()  const { return _young_generation;  }
461   ShenandoahGeneration*      global_generation() const { return _global_generation; }
462   ShenandoahGeneration*      old_generation()    const { return _old_generation;    }
463   ShenandoahGeneration*      generation_for(ShenandoahRegionAffiliation affiliation) const;
464 
465   ShenandoahCollectorPolicy* shenandoah_policy() const { return _shenandoah_policy; }
466   ShenandoahMode*            mode()              const { return _gc_mode;           }
467   ShenandoahFreeSet*         free_set()          const { return _free_set;          }
468   ShenandoahPacer*           pacer()             const { return _pacer;             }
469 
470   ShenandoahPhaseTimings*    phase_timings()     const { return _phase_timings;     }
471 
472   ShenandoahVerifier*        verifier();
473 
474 // ---------- VM subsystem bindings
475 //
476 private:
477   ShenandoahMonitoringSupport* _monitoring_support;
478   MemoryPool*                  _memory_pool;
479   GCMemoryManager              _stw_memory_manager;
480   GCMemoryManager              _cycle_memory_manager;
481   ConcurrentGCTimer*           _gc_timer;
482   SoftRefPolicy                _soft_ref_policy;
483 
484   // For exporting to SA
485   int                          _log_min_obj_alignment_in_bytes;
486 public:
487   ShenandoahMonitoringSupport* monitoring_support() { return _monitoring_support;    }
488   GCMemoryManager* cycle_memory_manager()           { return &_cycle_memory_manager; }
489   GCMemoryManager* stw_memory_manager()             { return &_stw_memory_manager;   }
490   SoftRefPolicy* soft_ref_policy()                  { return &_soft_ref_policy;      }
491 
492   GrowableArray<GCMemoryManager*> memory_managers();
493   GrowableArray<MemoryPool*> memory_pools();
494   MemoryUsage memory_usage();
495   GCTracer* tracer();
496   ConcurrentGCTimer* gc_timer() const;
497 
498 // ---------- Class Unloading
499 //
500 private:
501   ShenandoahSharedFlag  _is_aging_cycle;
502   ShenandoahSharedFlag _unload_classes;
503   ShenandoahUnload     _unloader;
504 
505 public:
506   void set_unload_classes(bool uc);
507   bool unload_classes() const;
508 
509   // Perform STW class unloading and weak root cleaning
510   void parallel_cleaning(bool full_gc);
511 
512 private:
513   void stw_unload_classes(bool full_gc);
514   void stw_process_weak_roots(bool full_gc);
515   void stw_weak_refs(bool full_gc);
516 
517   // Heap iteration support
518   void scan_roots_for_iteration(ShenandoahScanObjectStack* oop_stack, ObjectIterateScanRootClosure* oops);
519   bool prepare_aux_bitmap_for_iteration();
520   void reclaim_aux_bitmap_for_iteration();
521 
522 // ---------- Generic interface hooks
523 // Minor things that super-interface expects us to implement to play nice with
524 // the rest of runtime. Some of the things here are not required to be implemented,
525 // and can be stubbed out.
526 //
527 public:
528   AdaptiveSizePolicy* size_policy() shenandoah_not_implemented_return(NULL);
529   bool is_maximal_no_gc() const shenandoah_not_implemented_return(false);
530 
531   bool is_in(const void* p) const;
532 
533   bool is_in_active_generation(oop obj) const;
534   bool is_in_young(const void* p) const;
535   bool is_in_old(const void* p) const;
536   inline bool is_old(oop pobj) const;
537 
538   MemRegion reserved_region() const { return _reserved; }
539   bool is_in_reserved(const void* addr) const { return _reserved.contains(addr); }
540 
541   void collect(GCCause::Cause cause);
542   void do_full_collection(bool clear_all_soft_refs);
543 
544   // Used for parsing heap during error printing
545   HeapWord* block_start(const void* addr) const;
546   bool block_is_obj(const HeapWord* addr) const;
547   bool print_location(outputStream* st, void* addr) const;
548 
549   // Used for native heap walkers: heap dumpers, mostly
550   void object_iterate(ObjectClosure* cl);
551   // Parallel heap iteration support
552   virtual ParallelObjectIterator* parallel_object_iterator(uint workers);
553 
554   // Keep alive an object that was loaded with AS_NO_KEEPALIVE.
555   void keep_alive(oop obj);
556 
557 // ---------- Safepoint interface hooks
558 //
559 public:
560   void safepoint_synchronize_begin();
561   void safepoint_synchronize_end();
562 
563 // ---------- Code roots handling hooks
564 //
565 public:
566   void register_nmethod(nmethod* nm);
567   void unregister_nmethod(nmethod* nm);
568   void flush_nmethod(nmethod* nm);
569   void verify_nmethod(nmethod* nm) {}
570 
571 // ---------- Pinning hooks
572 //
573 public:
574   // Shenandoah supports per-object (per-region) pinning
575   bool supports_object_pinning() const { return true; }
576 
577   oop pin_object(JavaThread* thread, oop obj);
578   void unpin_object(JavaThread* thread, oop obj);
579 
580   void sync_pinned_region_status();
581   void assert_pinned_region_status() NOT_DEBUG_RETURN;
582 
583 // ---------- Concurrent Stack Processing support
584 //
585 public:
586   bool uses_stack_watermark_barrier() const { return true; }
587 
588 // ---------- Allocation support
589 //
590 private:
591   HeapWord* allocate_memory_under_lock(ShenandoahAllocRequest& request, bool& in_new_region);
592 
593   inline HeapWord* allocate_from_gclab(Thread* thread, size_t size);
594   HeapWord* allocate_from_gclab_slow(Thread* thread, size_t size);
595   HeapWord* allocate_new_gclab(size_t min_size, size_t word_size, size_t* actual_size);
596 
597   inline HeapWord* allocate_from_plab(Thread* thread, size_t size);
598   HeapWord* allocate_from_plab_slow(Thread* thread, size_t size);
599   HeapWord* allocate_new_plab(size_t min_size, size_t word_size, size_t* actual_size);
600 
601 public:
602   HeapWord* allocate_memory(ShenandoahAllocRequest& request);
603   HeapWord* mem_allocate(size_t size, bool* what);
604   MetaWord* satisfy_failed_metadata_allocation(ClassLoaderData* loader_data,
605                                                size_t size,
606                                                Metaspace::MetadataType mdtype);
607 
608   void notify_mutator_alloc_words(size_t words, bool waste);
609 
610   HeapWord* allocate_new_tlab(size_t min_size, size_t requested_size, size_t* actual_size);
611   size_t tlab_capacity(Thread *thr) const;
612   size_t unsafe_max_tlab_alloc(Thread *thread) const;
613   size_t max_tlab_size() const;
614   size_t tlab_used(Thread* ignored) const;
615 
616   void ensure_parsability(bool retire_labs);
617 
618   void labs_make_parsable();
619   void tlabs_retire(bool resize);
620   void gclabs_retire(bool resize);
621 
622   void set_young_lab_region_flags();
623 
624 // ---------- Marking support
625 //
626 private:
627   ShenandoahMarkingContext* _marking_context;
628   MemRegion  _bitmap_region;
629   MemRegion  _aux_bitmap_region;
630   MarkBitMap _verification_bit_map;
631   MarkBitMap _aux_bit_map;
632 
633   size_t _bitmap_size;
634   size_t _bitmap_regions_per_slice;
635   size_t _bitmap_bytes_per_slice;
636 
637   size_t _pretouch_heap_page_size;
638   size_t _pretouch_bitmap_page_size;
639 
640   bool _bitmap_region_special;
641   bool _aux_bitmap_region_special;
642 
643   ShenandoahLiveData** _liveness_cache;
644 
645 public:
646   inline ShenandoahMarkingContext* complete_marking_context() const;
647   inline ShenandoahMarkingContext* marking_context() const;
648 
649   template<class T>
650   inline void marked_object_iterate(ShenandoahHeapRegion* region, T* cl);
651 
652   template<class T>
653   inline void marked_object_iterate(ShenandoahHeapRegion* region, T* cl, HeapWord* limit);
654 
655   template<class T>
656   inline void marked_object_oop_iterate(ShenandoahHeapRegion* region, T* cl, HeapWord* limit);
657 
658   // SATB barriers hooks
659   inline bool requires_marking(const void* entry) const;
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   ShenandoahLiveData* get_liveness_cache(uint worker_id);
668   void flush_liveness_cache(uint worker_id);
669 
670   size_t pretouch_heap_page_size() { return _pretouch_heap_page_size; }
671 
672 // ---------- Evacuation support
673 //
674 private:
675   ShenandoahCollectionSet* _collection_set;
676   ShenandoahEvacOOMHandler _oom_evac_handler;
677   ShenandoahSharedFlag _old_gen_oom_evac;
678 
679   inline oop try_evacuate_object(oop src, Thread* thread, ShenandoahHeapRegion* from_region, ShenandoahRegionAffiliation target_gen);
680   void handle_old_evacuation(HeapWord* obj, size_t words, bool promotion);
681   void handle_old_evacuation_failure();
682   void handle_promotion_failure();
683 
684 public:
685   static address in_cset_fast_test_addr();
686 
687   ShenandoahCollectionSet* collection_set() const { return _collection_set; }
688 
689   // Checks if object is in the collection set.
690   inline bool in_collection_set(oop obj) const;
691 
692   // Checks if location is in the collection set. Can be interior pointer, not the oop itself.
693   inline bool in_collection_set_loc(void* loc) const;
694 
695   // Evacuates or promotes object src. Returns the evacuated object, either evacuated
696   // by this thread, or by some other thread.
697   inline oop evacuate_object(oop src, Thread* thread);
698 
699   // Call before/after evacuation.
700   inline void enter_evacuation(Thread* t);
701   inline void leave_evacuation(Thread* t);
702 
703   inline bool clear_old_evacuation_failure();
704 
705 // ---------- Generational support
706 //
707 private:
708   RememberedScanner* _card_scan;
709 
710 public:
711   inline RememberedScanner* card_scan() { return _card_scan; }
712   void clear_cards_for(ShenandoahHeapRegion* region);
713   void dirty_cards(HeapWord* start, HeapWord* end);
714   void clear_cards(HeapWord* start, HeapWord* end);
715   void mark_card_as_dirty(void* location);
716   void retire_plab(PLAB* plab);
717   void cancel_mixed_collections();
718   void coalesce_and_fill_old_regions();
719 
720 // ---------- Helper functions
721 //
722 public:
723   template <class T>
724   inline void conc_update_with_forwarded(T* p);
725 
726   template <class T>
727   inline void update_with_forwarded(T* p);
728 
729   static inline void atomic_update_oop(oop update,       oop* addr,       oop compare);
730   static inline void atomic_update_oop(oop update, narrowOop* addr,       oop compare);
731   static inline void atomic_update_oop(oop update, narrowOop* addr, narrowOop compare);
732 
733   static inline bool atomic_update_oop_check(oop update,       oop* addr,       oop compare);
734   static inline bool atomic_update_oop_check(oop update, narrowOop* addr,       oop compare);
735   static inline bool atomic_update_oop_check(oop update, narrowOop* addr, narrowOop compare);
736 
737   static inline void atomic_clear_oop(      oop* addr,       oop compare);
738   static inline void atomic_clear_oop(narrowOop* addr,       oop compare);
739   static inline void atomic_clear_oop(narrowOop* addr, narrowOop compare);
740 
741   size_t trash_humongous_region_at(ShenandoahHeapRegion *r);
742 
743   static inline void increase_object_age(oop obj, uint additional_age);
744 
745   void purge_old_satb_buffers(bool abandon);
746 private:
747   void trash_cset_regions();
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