< prev index next >

src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp

Print this page

 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/shenandoahPadding.hpp"
 36 #include "gc/shenandoah/shenandoahSharedVariables.hpp"
 37 #include "gc/shenandoah/shenandoahUnload.hpp"

 38 #include "memory/metaspace.hpp"
 39 #include "services/memoryManager.hpp"
 40 #include "utilities/globalDefinitions.hpp"
 41 #include "utilities/stack.hpp"
 42 
 43 class ConcurrentGCTimer;
 44 class ObjectIterateScanRootClosure;

 45 class ShenandoahCollectorPolicy;
 46 class ShenandoahControlThread;

 47 class ShenandoahGCSession;
 48 class ShenandoahGCStateResetter;



 49 class ShenandoahHeuristics;

 50 class ShenandoahMarkingContext;
 51 class ShenandoahMode;
 52 class ShenandoahPhaseTimings;
 53 class ShenandoahHeap;
 54 class ShenandoahHeapRegion;
 55 class ShenandoahHeapRegionClosure;
 56 class ShenandoahCollectionSet;
 57 class ShenandoahFreeSet;
 58 class ShenandoahConcurrentMark;
 59 class ShenandoahFullGC;
 60 class ShenandoahMonitoringSupport;
 61 class ShenandoahPacer;
 62 class ShenandoahReferenceProcessor;
 63 class ShenandoahVerifier;
 64 class ShenandoahWorkerThreads;
 65 class VMStructs;
 66 
 67 // Used for buffering per-region liveness data.
 68 // Needed since ShenandoahHeapRegion uses atomics to update liveness.
 69 // The ShenandoahHeap array has max-workers elements, each of which is an array of
 70 // uint16_t * max_regions. The choice of uint16_t is not accidental:
 71 // there is a tradeoff between static/dynamic footprint that translates

 90   ShenandoahRegionIterator(ShenandoahHeap* heap);
 91 
 92   // Reset iterator to default state
 93   void reset();
 94 
 95   // Returns next region, or NULL if there are no more regions.
 96   // This is multi-thread-safe.
 97   inline ShenandoahHeapRegion* next();
 98 
 99   // This is *not* MT safe. However, in the absence of multithreaded access, it
100   // can be used to determine if there is more work to do.
101   bool has_next() const;
102 };
103 
104 class ShenandoahHeapRegionClosure : public StackObj {
105 public:
106   virtual void heap_region_do(ShenandoahHeapRegion* r) = 0;
107   virtual bool is_thread_safe() { return false; }
108 };
109 










110 typedef ShenandoahLock    ShenandoahHeapLock;
111 typedef ShenandoahLocker  ShenandoahHeapLocker;
112 typedef Stack<oop, mtGC>  ShenandoahScanObjectStack;
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 ShenandoahParallelObjectIterator;
124   friend class ShenandoahSafepoint;
125   // Supported GC
126   friend class ShenandoahConcurrentGC;

127   friend class ShenandoahDegenGC;
128   friend class ShenandoahFullGC;
129   friend class ShenandoahUnload;
130 
131 // ---------- Locks that guard important data structures in Heap
132 //
133 private:
134   ShenandoahHeapLock _lock;




135 
136 public:
137   ShenandoahHeapLock* lock() {
138     return &_lock;
139   }
140 















141 // ---------- Initialization, termination, identification, printing routines
142 //
143 public:
144   static ShenandoahHeap* heap();
145 
146   const char* name()          const { return "Shenandoah"; }
147   ShenandoahHeap::Name kind() const { return CollectedHeap::Shenandoah; }
148 
149   ShenandoahHeap(ShenandoahCollectorPolicy* policy);
150   jint initialize();
151   void post_initialize();
152   void initialize_mode();
153   void initialize_heuristics();

154 
155   void initialize_serviceability();
156 
157   void print_on(outputStream* st)              const;
158   void print_extended_on(outputStream *st)     const;
159   void print_tracing_info()                    const;
160   void print_heap_regions_on(outputStream* st) const;
161 
162   void stop();
163 
164   void prepare_for_verify();
165   void verify(VerifyOption vo);



166 
167 // WhiteBox testing support.
168   bool supports_concurrent_gc_breakpoints() const {
169     return true;
170   }
171 
172 // ---------- Heap counters and metrics
173 //
174 private:
175            size_t _initial_size;
176            size_t _minimum_size;
177   volatile size_t _soft_max_size;
178   shenandoah_padding(0);
179   volatile size_t _used;
180   volatile size_t _committed;
181   volatile size_t _bytes_allocated_since_gc_start;
182   shenandoah_padding(1);
183 




184 public:
185   void increase_used(size_t bytes);
186   void decrease_used(size_t bytes);
187   void set_used(size_t bytes);
188 
189   void increase_committed(size_t bytes);
190   void decrease_committed(size_t bytes);
191   void increase_allocated(size_t bytes);
192 
193   size_t bytes_allocated_since_gc_start();
194   void reset_bytes_allocated_since_gc_start();
195 
196   size_t min_capacity()      const;
197   size_t max_capacity()      const;
198   size_t soft_max_capacity() const;
199   size_t initial_capacity()  const;
200   size_t capacity()          const;
201   size_t used()              const;
202   size_t committed()         const;
203 
204   void set_soft_max_capacity(size_t v);
205 
206 // ---------- Workers handling
207 //
208 private:
209   uint _max_workers;
210   ShenandoahWorkerThreads* _workers;
211   ShenandoahWorkerThreads* _safepoint_workers;
212 
213 public:

240 
241   inline ShenandoahHeapRegion* const get_region(size_t region_idx) const;
242 
243   void heap_region_iterate(ShenandoahHeapRegionClosure* blk) const;
244   void parallel_heap_region_iterate(ShenandoahHeapRegionClosure* blk) const;
245 
246 // ---------- GC state machinery
247 //
248 // GC state describes the important parts of collector state, that may be
249 // used to make barrier selection decisions in the native and generated code.
250 // Multiple bits can be set at once.
251 //
252 // Important invariant: when GC state is zero, the heap is stable, and no barriers
253 // are required.
254 //
255 public:
256   enum GCStateBitPos {
257     // Heap has forwarded objects: needs LRB barriers.
258     HAS_FORWARDED_BITPOS   = 0,
259 
260     // Heap is under marking: needs SATB barriers.
261     MARKING_BITPOS    = 1,
262 
263     // Heap is under evacuation: needs LRB barriers. (Set together with HAS_FORWARDED)
264     EVACUATION_BITPOS = 2,
265 
266     // Heap is under updating: needs no additional barriers.
267     UPDATEREFS_BITPOS = 3,
268 
269     // Heap is under weak-reference/roots processing: needs weak-LRB barriers.
270     WEAK_ROOTS_BITPOS  = 4,



271   };
272 
273   enum GCState {
274     STABLE        = 0,
275     HAS_FORWARDED = 1 << HAS_FORWARDED_BITPOS,
276     MARKING       = 1 << MARKING_BITPOS,
277     EVACUATION    = 1 << EVACUATION_BITPOS,
278     UPDATEREFS    = 1 << UPDATEREFS_BITPOS,
279     WEAK_ROOTS    = 1 << WEAK_ROOTS_BITPOS,

280   };
281 
282 private:
283   ShenandoahSharedBitmap _gc_state;
284   ShenandoahSharedFlag   _degenerated_gc_in_progress;
285   ShenandoahSharedFlag   _full_gc_in_progress;
286   ShenandoahSharedFlag   _full_gc_move_in_progress;
287   ShenandoahSharedFlag   _progress_last_gc;
288   ShenandoahSharedFlag   _concurrent_strong_root_in_progress;
289 















































290   void set_gc_state_all_threads(char state);
291   void set_gc_state_mask(uint mask, bool value);
292 


293 public:
294   char gc_state() const;
295   static address gc_state_addr();
296 
297   void set_concurrent_mark_in_progress(bool in_progress);

298   void set_evacuation_in_progress(bool in_progress);
299   void set_update_refs_in_progress(bool in_progress);
300   void set_degenerated_gc_in_progress(bool in_progress);
301   void set_full_gc_in_progress(bool in_progress);
302   void set_full_gc_move_in_progress(bool in_progress);
303   void set_has_forwarded_objects(bool cond);
304   void set_concurrent_strong_root_in_progress(bool cond);
305   void set_concurrent_weak_root_in_progress(bool cond);


306 
307   inline bool is_stable() const;
308   inline bool is_idle() const;
309   inline bool is_concurrent_mark_in_progress() const;


310   inline bool is_update_refs_in_progress() const;
311   inline bool is_evacuation_in_progress() const;
312   inline bool is_degenerated_gc_in_progress() const;
313   inline bool is_full_gc_in_progress() const;
314   inline bool is_full_gc_move_in_progress() const;
315   inline bool has_forwarded_objects() const;
316   inline bool is_gc_in_progress_mask(uint mask) const;
317   inline bool is_stw_gc_in_progress() const;
318   inline bool is_concurrent_strong_root_in_progress() const;
319   inline bool is_concurrent_weak_root_in_progress() const;



































320 
321 private:


322   enum CancelState {
323     // Normal state. GC has not been cancelled and is open for cancellation.
324     // Worker threads can suspend for safepoint.
325     CANCELLABLE,
326 
327     // GC has been cancelled. Worker threads can not suspend for
328     // safepoint but must finish their work as soon as possible.
329     CANCELLED,
330 
331     // GC has not been cancelled and must not be cancelled. At least
332     // one worker thread checks for pending safepoint and may suspend
333     // if a safepoint is pending.
334     NOT_CANCELLED
335   };
336 

337   ShenandoahSharedEnumFlag<CancelState> _cancelled_gc;





338   bool try_cancel_gc();
339 
340 public:
341   static address cancelled_gc_addr();
342 
343   inline bool cancelled_gc() const;
344   inline bool check_cancelled_gc_and_yield(bool sts_active = true);
345 
346   inline void clear_cancelled_gc();
347 

348   void cancel_gc(GCCause::Cause cause);
349 
350 public:
351   // Elastic heap support
352   void entry_uncommit(double shrink_before, size_t shrink_until);
353   void op_uncommit(double shrink_before, size_t shrink_until);
354 
355 private:
356   // GC support
357   // Reset bitmap, prepare regions for new GC cycle
358   void prepare_gc();
359   void prepare_regions_and_collection_set(bool concurrent);
360   // Evacuation
361   void prepare_evacuation(bool concurrent);
362   void evacuate_collection_set(bool concurrent);
363   // Concurrent root processing
364   void prepare_concurrent_roots();
365   void finish_concurrent_roots();
366   // Concurrent class unloading support
367   void do_class_unloading();
368   // Reference updating
369   void prepare_update_heap_references(bool concurrent);
370   void update_heap_references(bool concurrent);
371   // Final update region states
372   void update_heap_region_states(bool concurrent);
373   void rebuild_free_set(bool concurrent);
374 
375   void rendezvous_threads();
376   void recycle_trash();
377 public:
378   void notify_gc_progress()    { _progress_last_gc.set();   }
379   void notify_gc_no_progress() { _progress_last_gc.unset(); }
380 
381 //
382 // Mark support
383 private:




384   ShenandoahControlThread*   _control_thread;

385   ShenandoahCollectorPolicy* _shenandoah_policy;
386   ShenandoahMode*            _gc_mode;
387   ShenandoahHeuristics*      _heuristics;
388   ShenandoahFreeSet*         _free_set;
389   ShenandoahPacer*           _pacer;
390   ShenandoahVerifier*        _verifier;
391 
392   ShenandoahPhaseTimings*    _phase_timings;
393 
394   ShenandoahControlThread*   control_thread()          { return _control_thread;    }

395 
396 public:





397   ShenandoahCollectorPolicy* shenandoah_policy() const { return _shenandoah_policy; }
398   ShenandoahMode*            mode()              const { return _gc_mode;           }
399   ShenandoahHeuristics*      heuristics()        const { return _heuristics;        }
400   ShenandoahFreeSet*         free_set()          const { return _free_set;          }
401   ShenandoahPacer*           pacer()             const { return _pacer;             }
402 
403   ShenandoahPhaseTimings*    phase_timings()     const { return _phase_timings;     }
404 
405   ShenandoahVerifier*        verifier();
406 
407 // ---------- VM subsystem bindings
408 //
409 private:
410   ShenandoahMonitoringSupport* _monitoring_support;
411   MemoryPool*                  _memory_pool;



412   GCMemoryManager              _stw_memory_manager;
413   GCMemoryManager              _cycle_memory_manager;
414   ConcurrentGCTimer*           _gc_timer;
415   SoftRefPolicy                _soft_ref_policy;
416 
417   // For exporting to SA
418   int                          _log_min_obj_alignment_in_bytes;
419 public:
420   ShenandoahMonitoringSupport* monitoring_support() { return _monitoring_support;    }
421   GCMemoryManager* cycle_memory_manager()           { return &_cycle_memory_manager; }
422   GCMemoryManager* stw_memory_manager()             { return &_stw_memory_manager;   }
423   SoftRefPolicy* soft_ref_policy()                  { return &_soft_ref_policy;      }
424 
425   GrowableArray<GCMemoryManager*> memory_managers();
426   GrowableArray<MemoryPool*> memory_pools();
427   MemoryUsage memory_usage();
428   GCTracer* tracer();
429   ConcurrentGCTimer* gc_timer() const;
430 
431 // ---------- Reference processing
432 //
433 private:
434   ShenandoahReferenceProcessor* const _ref_processor;
435 
436 public:
437   ShenandoahReferenceProcessor* ref_processor() { return _ref_processor; }
438 
439 // ---------- Class Unloading
440 //
441 private:

442   ShenandoahSharedFlag _unload_classes;
443   ShenandoahUnload     _unloader;
444 
445 public:
446   void set_unload_classes(bool uc);
447   bool unload_classes() const;
448 
449   // Perform STW class unloading and weak root cleaning
450   void parallel_cleaning(bool full_gc);
451 
452 private:
453   void stw_unload_classes(bool full_gc);
454   void stw_process_weak_roots(bool full_gc);
455   void stw_weak_refs(bool full_gc);
456 
457   // Heap iteration support
458   void scan_roots_for_iteration(ShenandoahScanObjectStack* oop_stack, ObjectIterateScanRootClosure* oops);
459   bool prepare_aux_bitmap_for_iteration();
460   void reclaim_aux_bitmap_for_iteration();
461 
462 // ---------- Generic interface hooks
463 // Minor things that super-interface expects us to implement to play nice with
464 // the rest of runtime. Some of the things here are not required to be implemented,
465 // and can be stubbed out.
466 //
467 public:
468   AdaptiveSizePolicy* size_policy() shenandoah_not_implemented_return(NULL);
469   bool is_maximal_no_gc() const shenandoah_not_implemented_return(false);
470 
471   bool is_in(const void* p) const;
472 





473   bool requires_barriers(stackChunkOop obj) const;
474 
475   MemRegion reserved_region() const { return _reserved; }
476   bool is_in_reserved(const void* addr) const { return _reserved.contains(addr); }
477 
478   void collect(GCCause::Cause cause);
479   void do_full_collection(bool clear_all_soft_refs);
480 
481   // Used for parsing heap during error printing
482   HeapWord* block_start(const void* addr) const;
483   bool block_is_obj(const HeapWord* addr) const;
484   bool print_location(outputStream* st, void* addr) const;
485 
486   // Used for native heap walkers: heap dumpers, mostly
487   void object_iterate(ObjectClosure* cl);
488   // Parallel heap iteration support
489   virtual ParallelObjectIteratorImpl* parallel_object_iterator(uint workers);
490 
491   // Keep alive an object that was loaded with AS_NO_KEEPALIVE.
492   void keep_alive(oop obj);

508 // ---------- Pinning hooks
509 //
510 public:
511   // Shenandoah supports per-object (per-region) pinning
512   bool supports_object_pinning() const { return true; }
513 
514   oop pin_object(JavaThread* thread, oop obj);
515   void unpin_object(JavaThread* thread, oop obj);
516 
517   void sync_pinned_region_status();
518   void assert_pinned_region_status() NOT_DEBUG_RETURN;
519 
520 // ---------- Concurrent Stack Processing support
521 //
522 public:
523   bool uses_stack_watermark_barrier() const { return true; }
524 
525 // ---------- Allocation support
526 //
527 private:
528   HeapWord* allocate_memory_under_lock(ShenandoahAllocRequest& request, bool& in_new_region);

529   inline HeapWord* allocate_from_gclab(Thread* thread, size_t size);
530   HeapWord* allocate_from_gclab_slow(Thread* thread, size_t size);
531   HeapWord* allocate_new_gclab(size_t min_size, size_t word_size, size_t* actual_size);
532 




533 public:
534   HeapWord* allocate_memory(ShenandoahAllocRequest& request);
535   HeapWord* mem_allocate(size_t size, bool* what);
536   MetaWord* satisfy_failed_metadata_allocation(ClassLoaderData* loader_data,
537                                                size_t size,
538                                                Metaspace::MetadataType mdtype);
539 
540   void notify_mutator_alloc_words(size_t words, bool waste);
541 
542   HeapWord* allocate_new_tlab(size_t min_size, size_t requested_size, size_t* actual_size);
543   size_t tlab_capacity(Thread *thr) const;
544   size_t unsafe_max_tlab_alloc(Thread *thread) const;
545   size_t max_tlab_size() const;
546   size_t tlab_used(Thread* ignored) const;
547 
548   void ensure_parsability(bool retire_labs);
549 
550   void labs_make_parsable();
551   void tlabs_retire(bool resize);
552   void gclabs_retire(bool resize);
553 


554 // ---------- Marking support
555 //
556 private:
557   ShenandoahMarkingContext* _marking_context;
558   MemRegion  _bitmap_region;
559   MemRegion  _aux_bitmap_region;
560   MarkBitMap _verification_bit_map;
561   MarkBitMap _aux_bit_map;
562 
563   size_t _bitmap_size;
564   size_t _bitmap_regions_per_slice;
565   size_t _bitmap_bytes_per_slice;
566 
567   size_t _pretouch_heap_page_size;
568   size_t _pretouch_bitmap_page_size;
569 
570   bool _bitmap_region_special;
571   bool _aux_bitmap_region_special;
572 
573   ShenandoahLiveData** _liveness_cache;
574 
575 public:
576   inline ShenandoahMarkingContext* complete_marking_context() const;
577   inline ShenandoahMarkingContext* marking_context() const;
578   inline void mark_complete_marking_context();
579   inline void mark_incomplete_marking_context();
580 
581   template<class T>
582   inline void marked_object_iterate(ShenandoahHeapRegion* region, T* cl);
583 
584   template<class T>
585   inline void marked_object_iterate(ShenandoahHeapRegion* region, T* cl, HeapWord* limit);
586 
587   template<class T>
588   inline void marked_object_oop_iterate(ShenandoahHeapRegion* region, T* cl, HeapWord* limit);
589 
590   void reset_mark_bitmap();
591 
592   // SATB barriers hooks
593   inline bool requires_marking(const void* entry) const;
594 
595   // Support for bitmap uncommits
596   bool commit_bitmap_slice(ShenandoahHeapRegion *r);
597   bool uncommit_bitmap_slice(ShenandoahHeapRegion *r);
598   bool is_bitmap_slice_committed(ShenandoahHeapRegion* r, bool skip_self = false);
599 
600   // Liveness caching support
601   ShenandoahLiveData* get_liveness_cache(uint worker_id);
602   void flush_liveness_cache(uint worker_id);
603 
604   size_t pretouch_heap_page_size() { return _pretouch_heap_page_size; }
605 
606 // ---------- Evacuation support
607 //
608 private:
609   ShenandoahCollectionSet* _collection_set;
610   ShenandoahEvacOOMHandler _oom_evac_handler;






611 
612 public:
613   static address in_cset_fast_test_addr();
614 
615   ShenandoahCollectionSet* collection_set() const { return _collection_set; }
616 
617   // Checks if object is in the collection set.
618   inline bool in_collection_set(oop obj) const;
619 
620   // Checks if location is in the collection set. Can be interior pointer, not the oop itself.
621   inline bool in_collection_set_loc(void* loc) const;
622 
623   // Evacuates object src. Returns the evacuated object, either evacuated
624   // by this thread, or by some other thread.
625   inline oop evacuate_object(oop src, Thread* thread);
626 
627   // Call before/after evacuation.
628   inline void enter_evacuation(Thread* t);
629   inline void leave_evacuation(Thread* t);
630 



















631 // ---------- Helper functions
632 //
633 public:
634   template <class T>
635   inline void conc_update_with_forwarded(T* p);
636 
637   template <class T>
638   inline void update_with_forwarded(T* p);
639 
640   static inline void atomic_update_oop(oop update,       oop* addr,       oop compare);
641   static inline void atomic_update_oop(oop update, narrowOop* addr,       oop compare);
642   static inline void atomic_update_oop(oop update, narrowOop* addr, narrowOop compare);
643 
644   static inline bool atomic_update_oop_check(oop update,       oop* addr,       oop compare);
645   static inline bool atomic_update_oop_check(oop update, narrowOop* addr,       oop compare);
646   static inline bool atomic_update_oop_check(oop update, narrowOop* addr, narrowOop compare);
647 
648   static inline void atomic_clear_oop(      oop* addr,       oop compare);
649   static inline void atomic_clear_oop(narrowOop* addr,       oop compare);
650   static inline void atomic_clear_oop(narrowOop* addr, narrowOop compare);
651 
652   void trash_humongous_region_at(ShenandoahHeapRegion *r);


653 

654 private:
655   void trash_cset_regions();
656 
657 // ---------- Testing helpers functions
658 //
659 private:
660   ShenandoahSharedFlag _inject_alloc_failure;
661 
662   void try_inject_alloc_failure();
663   bool should_inject_alloc_failure();
664 };
665 
666 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHHEAP_HPP

 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 ShenandoahOldGeneration;
 56 class ShenandoahHeuristics;
 57 class ShenandoahOldHeuristics;
 58 class ShenandoahMarkingContext;

 59 class ShenandoahPhaseTimings;
 60 class ShenandoahHeap;
 61 class ShenandoahHeapRegion;
 62 class ShenandoahHeapRegionClosure;
 63 class ShenandoahCollectionSet;
 64 class ShenandoahFreeSet;
 65 class ShenandoahConcurrentMark;
 66 class ShenandoahFullGC;
 67 class ShenandoahMonitoringSupport;
 68 class ShenandoahPacer;
 69 class ShenandoahReferenceProcessor;
 70 class ShenandoahVerifier;
 71 class ShenandoahWorkerThreads;
 72 class VMStructs;
 73 
 74 // Used for buffering per-region liveness data.
 75 // Needed since ShenandoahHeapRegion uses atomics to update liveness.
 76 // The ShenandoahHeap array has max-workers elements, each of which is an array of
 77 // uint16_t * max_regions. The choice of uint16_t is not accidental:
 78 // there is a tradeoff between static/dynamic footprint that translates

 97   ShenandoahRegionIterator(ShenandoahHeap* heap);
 98 
 99   // Reset iterator to default state
100   void reset();
101 
102   // Returns next region, or NULL if there are no more regions.
103   // This is multi-thread-safe.
104   inline ShenandoahHeapRegion* next();
105 
106   // This is *not* MT safe. However, in the absence of multithreaded access, it
107   // can be used to determine if there is more work to do.
108   bool has_next() const;
109 };
110 
111 class ShenandoahHeapRegionClosure : public StackObj {
112 public:
113   virtual void heap_region_do(ShenandoahHeapRegion* r) = 0;
114   virtual bool is_thread_safe() { return false; }
115 };
116 
117 template<GenerationMode GENERATION>
118 class ShenandoahGenerationRegionClosure : public ShenandoahHeapRegionClosure {
119  public:
120   explicit ShenandoahGenerationRegionClosure(ShenandoahHeapRegionClosure* cl) : _cl(cl) {}
121   void heap_region_do(ShenandoahHeapRegion* r);
122   virtual bool is_thread_safe() { return _cl->is_thread_safe(); }
123  private:
124   ShenandoahHeapRegionClosure* _cl;
125 };
126 
127 typedef ShenandoahLock    ShenandoahHeapLock;
128 typedef ShenandoahLocker  ShenandoahHeapLocker;
129 typedef Stack<oop, mtGC>  ShenandoahScanObjectStack;
130 
131 // Shenandoah GC is low-pause concurrent GC that uses Brooks forwarding pointers
132 // to encode forwarding data. See BrooksPointer for details on forwarding data encoding.
133 // See ShenandoahControlThread for GC cycle structure.
134 //
135 class ShenandoahHeap : public CollectedHeap {
136   friend class ShenandoahAsserts;
137   friend class VMStructs;
138   friend class ShenandoahGCSession;
139   friend class ShenandoahGCStateResetter;
140   friend class ShenandoahParallelObjectIterator;
141   friend class ShenandoahSafepoint;
142   // Supported GC
143   friend class ShenandoahConcurrentGC;
144   friend class ShenandoahOldGC;
145   friend class ShenandoahDegenGC;
146   friend class ShenandoahFullGC;
147   friend class ShenandoahUnload;
148 
149 // ---------- Locks that guard important data structures in Heap
150 //
151 private:
152   ShenandoahHeapLock _lock;
153   ShenandoahGeneration* _gc_generation;
154 
155   // true iff we are concurrently coalescing and filling old-gen HeapRegions
156   bool _prepare_for_old_mark;
157 
158 public:
159   ShenandoahHeapLock* lock() {
160     return &_lock;
161   }
162 
163   ShenandoahGeneration* active_generation() const {
164     // last or latest generation might be a better name here.
165     return _gc_generation;
166   }
167 
168   void set_gc_generation(ShenandoahGeneration* generation) {
169     _gc_generation = generation;
170   }
171 
172   ShenandoahOldHeuristics* old_heuristics();
173 
174   bool doing_mixed_evacuations();
175   bool is_old_bitmap_stable() const;
176   bool is_gc_generation_young() const;
177 
178 // ---------- Initialization, termination, identification, printing routines
179 //
180 public:
181   static ShenandoahHeap* heap();
182 
183   const char* name()          const { return "Shenandoah"; }
184   ShenandoahHeap::Name kind() const { return CollectedHeap::Shenandoah; }
185 
186   ShenandoahHeap(ShenandoahCollectorPolicy* policy);
187   jint initialize();
188   void post_initialize();
189   void initialize_mode();
190   void initialize_heuristics();
191   void initialize_generations();
192 
193   void initialize_serviceability();
194 
195   void print_on(outputStream* st)              const;
196   void print_extended_on(outputStream *st)     const;
197   void print_tracing_info()                    const;
198   void print_heap_regions_on(outputStream* st) const;
199 
200   void stop();
201 
202   void prepare_for_verify();
203   void verify(VerifyOption vo);
204   void verify_rem_set_at_mark();
205   void verify_rem_set_at_update_ref();
206   void verify_rem_set_after_full_gc();
207 
208 // WhiteBox testing support.
209   bool supports_concurrent_gc_breakpoints() const {
210     return true;
211   }
212 
213 // ---------- Heap counters and metrics
214 //
215 private:
216            size_t _initial_size;
217            size_t _minimum_size;
218   volatile size_t _soft_max_size;
219   shenandoah_padding(0);
220   volatile size_t _used;
221   volatile size_t _committed;

222   shenandoah_padding(1);
223 
224   static size_t young_generation_capacity(size_t total_capacity);
225   void help_verify_region_rem_set(ShenandoahHeapRegion* r, ShenandoahMarkingContext* ctx,
226                                   HeapWord* from, HeapWord* top, HeapWord* update_watermark, const char* message);
227 
228 public:
229   void increase_used(size_t bytes);
230   void decrease_used(size_t bytes);
231   void set_used(size_t bytes);
232 
233   void increase_committed(size_t bytes);
234   void decrease_committed(size_t bytes);

235 

236   void reset_bytes_allocated_since_gc_start();
237 
238   size_t min_capacity()      const;
239   size_t max_capacity()      const;
240   size_t soft_max_capacity() const;
241   size_t initial_capacity()  const;
242   size_t capacity()          const;
243   size_t used()              const;
244   size_t committed()         const;
245 
246   void set_soft_max_capacity(size_t v);
247 
248 // ---------- Workers handling
249 //
250 private:
251   uint _max_workers;
252   ShenandoahWorkerThreads* _workers;
253   ShenandoahWorkerThreads* _safepoint_workers;
254 
255 public:

282 
283   inline ShenandoahHeapRegion* const get_region(size_t region_idx) const;
284 
285   void heap_region_iterate(ShenandoahHeapRegionClosure* blk) const;
286   void parallel_heap_region_iterate(ShenandoahHeapRegionClosure* blk) const;
287 
288 // ---------- GC state machinery
289 //
290 // GC state describes the important parts of collector state, that may be
291 // used to make barrier selection decisions in the native and generated code.
292 // Multiple bits can be set at once.
293 //
294 // Important invariant: when GC state is zero, the heap is stable, and no barriers
295 // are required.
296 //
297 public:
298   enum GCStateBitPos {
299     // Heap has forwarded objects: needs LRB barriers.
300     HAS_FORWARDED_BITPOS   = 0,
301 
302     // Young regions are under marking: needs SATB barriers.
303     YOUNG_MARKING_BITPOS    = 1,
304 
305     // Heap is under evacuation: needs LRB barriers. (Set together with HAS_FORWARDED)
306     EVACUATION_BITPOS = 2,
307 
308     // Heap is under updating: needs no additional barriers.
309     UPDATEREFS_BITPOS = 3,
310 
311     // Heap is under weak-reference/roots processing: needs weak-LRB barriers.
312     WEAK_ROOTS_BITPOS  = 4,
313 
314     // Old regions are under marking, still need SATB barriers.
315     OLD_MARKING_BITPOS = 5
316   };
317 
318   enum GCState {
319     STABLE        = 0,
320     HAS_FORWARDED = 1 << HAS_FORWARDED_BITPOS,
321     YOUNG_MARKING = 1 << YOUNG_MARKING_BITPOS,
322     EVACUATION    = 1 << EVACUATION_BITPOS,
323     UPDATEREFS    = 1 << UPDATEREFS_BITPOS,
324     WEAK_ROOTS    = 1 << WEAK_ROOTS_BITPOS,
325     OLD_MARKING   = 1 << OLD_MARKING_BITPOS
326   };
327 
328 private:
329   ShenandoahSharedBitmap _gc_state;
330   ShenandoahSharedFlag   _degenerated_gc_in_progress;
331   ShenandoahSharedFlag   _full_gc_in_progress;
332   ShenandoahSharedFlag   _full_gc_move_in_progress;
333   ShenandoahSharedFlag   _progress_last_gc;
334   ShenandoahSharedFlag   _concurrent_strong_root_in_progress;
335 
336   // _alloc_supplement_reserve is a supplemental budget for new_memory allocations.  During evacuation and update-references,
337   // mutator allocation requests are "authorized" iff young_gen->available() plus _alloc_supplement_reserve minus
338   // _young_evac_reserve is greater than request size.  The values of _alloc_supplement_reserve and _young_evac_reserve
339   // are zero except during evacuation and update-reference phases of GC.  Both of these values are established at
340   // the start of evacuation, and they remain constant throughout the duration of these two phases of GC.  Since these
341   // two values are constant throughout each GC phases, we introduce a new service into ShenandoahGeneration.  This service
342   // provides adjusted_available() based on an adjusted capacity.  At the start of evacuation, we adjust young capacity by
343   // adding the amount to be borrowed from old-gen and subtracting the _young_evac_reserve, we adjust old capacity by
344   // subtracting the amount to be loaned to young-gen.
345   //
346   // We always use adjusted capacities to determine permission to allocate within young and to promote into old.  Note
347   // that adjusted capacities equal traditional capacities except during evacuation and update refs.
348   //
349   // During evacuation, we assure that _old_evac_expended does not exceed _old_evac_reserve.
350   //
351   // At the end of update references, we perform the following bookkeeping activities:
352   //
353   // 1. Unadjust the capacity within young-gen and old-gen to undo the effects of borrowing memory from old-gen.  Note that
354   //    the entirety of the collection set is now available, so allocation capacity naturally increase at this time.
355   // 2. Clear (reset to zero) _alloc_supplement_reserve, _young_evac_reserve, _old_evac_reserve, and _promoted_reserve
356   //
357   // _young_evac_reserve and _old_evac_reserve are only non-zero during evacuation and update-references.
358   //
359   // Allocation of old GCLABs assures that _old_evac_expended + request-size < _old_evac_reserved.  If the allocation
360   //  is authorized, increment _old_evac_expended by request size.  This allocation ignores old_gen->available().
361   //
362   // Note that the typical total expenditure on evacuation is less than the associated evacuation reserve because we generally
363   // reserve ShenandoahEvacWaste (> 1.0) times the anticipated evacuation need.  In the case that there is an excessive amount
364   // of waste, it may be that one thread fails to grab a new GCLAB, this does not necessarily doom the associated evacuation
365   // effort.  If this happens, the requesting thread blocks until some other thread manages to evacuate the offending object.
366   // Only after "all" threads fail to evacuate an object do we consider the evacuation effort to have failed.
367 
368   intptr_t _alloc_supplement_reserve;  // Bytes reserved for young allocations during evac and update refs
369   size_t _promoted_reserve;            // Bytes reserved within old-gen to hold the results of promotion
370   volatile size_t _promoted_expended;  // Bytes of old-gen memory expended on promotions
371 
372   size_t _old_evac_reserve;            // Bytes reserved within old-gen to hold evacuated objects from old-gen collection set
373   volatile size_t _old_evac_expended;  // Bytes of old-gen memory expended on old-gen evacuations
374 
375   size_t _young_evac_reserve;          // Bytes reserved within young-gen to hold evacuated objects from young-gen collection set
376 
377   size_t _captured_old_usage;          // What was old usage (bytes) when last captured?
378 
379   size_t _previous_promotion;          // Bytes promoted during previous evacuation
380 
381   bool _upgraded_to_full;
382 
383   void set_gc_state_all_threads(char state);
384   void set_gc_state_mask(uint mask, bool value);
385 
386 
387 
388 public:
389   char gc_state() const;
390   static address gc_state_addr();
391 
392   void set_concurrent_young_mark_in_progress(bool in_progress);
393   void set_concurrent_old_mark_in_progress(bool in_progress);
394   void set_evacuation_in_progress(bool in_progress);
395   void set_update_refs_in_progress(bool in_progress);
396   void set_degenerated_gc_in_progress(bool in_progress);
397   void set_full_gc_in_progress(bool in_progress);
398   void set_full_gc_move_in_progress(bool in_progress);
399   void set_has_forwarded_objects(bool cond);
400   void set_concurrent_strong_root_in_progress(bool cond);
401   void set_concurrent_weak_root_in_progress(bool cond);
402   void set_prepare_for_old_mark_in_progress(bool cond);
403   void set_aging_cycle(bool cond);
404 
405   inline bool is_stable() const;
406   inline bool is_idle() const;
407   inline bool is_concurrent_mark_in_progress() const;
408   inline bool is_concurrent_young_mark_in_progress() const;
409   inline bool is_concurrent_old_mark_in_progress() const;
410   inline bool is_update_refs_in_progress() const;
411   inline bool is_evacuation_in_progress() const;
412   inline bool is_degenerated_gc_in_progress() const;
413   inline bool is_full_gc_in_progress() const;
414   inline bool is_full_gc_move_in_progress() const;
415   inline bool has_forwarded_objects() const;
416   inline bool is_gc_in_progress_mask(uint mask) const;
417   inline bool is_stw_gc_in_progress() const;
418   inline bool is_concurrent_strong_root_in_progress() const;
419   inline bool is_concurrent_weak_root_in_progress() const;
420   inline bool is_prepare_for_old_mark_in_progress() const;
421   inline bool is_aging_cycle() const;
422   inline bool upgraded_to_full() { return _upgraded_to_full; }
423   inline void start_conc_gc() { _upgraded_to_full = false; }
424   inline void record_upgrade_to_full() { _upgraded_to_full = true; }
425 
426   inline size_t capture_old_usage(size_t usage);
427   inline void set_previous_promotion(size_t promoted_bytes);
428   inline size_t get_previous_promotion() const;
429 
430   // Returns previous value
431   inline size_t set_promoted_reserve(size_t new_val);
432   inline size_t get_promoted_reserve() const;
433 
434   inline void reset_promoted_expended();
435   inline size_t expend_promoted(size_t increment);
436   inline size_t unexpend_promoted(size_t decrement);
437   inline size_t get_promoted_expended();
438 
439   // Returns previous value
440   inline size_t set_old_evac_reserve(size_t new_val);
441   inline size_t get_old_evac_reserve() const;
442 
443   inline void reset_old_evac_expended();
444   inline size_t expend_old_evac(size_t increment);
445   inline size_t get_old_evac_expended();
446 
447   // Returns previous value
448   inline size_t set_young_evac_reserve(size_t new_val);
449   inline size_t get_young_evac_reserve() const;
450 
451   // Returns previous value.  This is a signed value because it is the amount borrowed minus the amount reserved for
452   // young-gen evacuation.  In case we cannot borrow much, this value might be negative.
453   inline intptr_t set_alloc_supplement_reserve(intptr_t new_val);
454   inline intptr_t get_alloc_supplement_reserve() const;
455 
456 private:
457   void manage_satb_barrier(bool active);
458 
459   enum CancelState {
460     // Normal state. GC has not been cancelled and is open for cancellation.
461     // Worker threads can suspend for safepoint.
462     CANCELLABLE,
463 
464     // GC has been cancelled. Worker threads can not suspend for
465     // safepoint but must finish their work as soon as possible.
466     CANCELLED,
467 
468     // GC has not been cancelled and must not be cancelled. At least
469     // one worker thread checks for pending safepoint and may suspend
470     // if a safepoint is pending.
471     NOT_CANCELLED
472   };
473 
474   double _cancel_requested_time;
475   ShenandoahSharedEnumFlag<CancelState> _cancelled_gc;
476 
477   // Returns true if cancel request was successfully communicated.
478   // Returns false if some other thread already communicated cancel
479   // request.  A true return value does not mean GC has been
480   // cancelled, only that the process of cancelling GC has begun.
481   bool try_cancel_gc();
482 
483 public:


484   inline bool cancelled_gc() const;
485   inline bool check_cancelled_gc_and_yield(bool sts_active = true);
486 
487   inline void clear_cancelled_gc(bool clear_oom_handler = true);
488 
489   void cancel_concurrent_mark();
490   void cancel_gc(GCCause::Cause cause);
491 
492 public:
493   // Elastic heap support
494   void entry_uncommit(double shrink_before, size_t shrink_until);
495   void op_uncommit(double shrink_before, size_t shrink_until);
496 
497 private:
498   // GC support



499   // Evacuation

500   void evacuate_collection_set(bool concurrent);
501   // Concurrent root processing
502   void prepare_concurrent_roots();
503   void finish_concurrent_roots();
504   // Concurrent class unloading support
505   void do_class_unloading();
506   // Reference updating
507   void prepare_update_heap_references(bool concurrent);
508   void update_heap_references(bool concurrent);
509   // Final update region states
510   void update_heap_region_states(bool concurrent);
511   void rebuild_free_set(bool concurrent);
512 
513   void rendezvous_threads();
514   void recycle_trash();
515 public:
516   void notify_gc_progress()    { _progress_last_gc.set();   }
517   void notify_gc_no_progress() { _progress_last_gc.unset(); }
518 
519 //
520 // Mark support
521 private:
522   ShenandoahYoungGeneration* _young_generation;
523   ShenandoahGeneration*      _global_generation;
524   ShenandoahOldGeneration*   _old_generation;
525 
526   ShenandoahControlThread*   _control_thread;
527   ShenandoahRegulatorThread* _regulator_thread;
528   ShenandoahCollectorPolicy* _shenandoah_policy;
529   ShenandoahMode*            _gc_mode;

530   ShenandoahFreeSet*         _free_set;
531   ShenandoahPacer*           _pacer;
532   ShenandoahVerifier*        _verifier;
533 
534   ShenandoahPhaseTimings*    _phase_timings;
535 
536   ShenandoahControlThread*   control_thread()          { return _control_thread;    }
537   ShenandoahRegulatorThread* regulator_thread()        { return _regulator_thread;  }
538 
539 public:
540   ShenandoahYoungGeneration* young_generation()  const { return _young_generation;  }
541   ShenandoahGeneration*      global_generation() const { return _global_generation; }
542   ShenandoahOldGeneration*   old_generation()    const { return _old_generation;    }
543   ShenandoahGeneration*      generation_for(ShenandoahRegionAffiliation affiliation) const;
544 
545   ShenandoahCollectorPolicy* shenandoah_policy() const { return _shenandoah_policy; }
546   ShenandoahMode*            mode()              const { return _gc_mode;           }

547   ShenandoahFreeSet*         free_set()          const { return _free_set;          }
548   ShenandoahPacer*           pacer()             const { return _pacer;             }
549 
550   ShenandoahPhaseTimings*    phase_timings()     const { return _phase_timings;     }
551 
552   ShenandoahVerifier*        verifier();
553 
554 // ---------- VM subsystem bindings
555 //
556 private:
557   ShenandoahMonitoringSupport* _monitoring_support;
558   MemoryPool*                  _memory_pool;
559   MemoryPool*                  _young_gen_memory_pool;
560   MemoryPool*                  _old_gen_memory_pool;
561 
562   GCMemoryManager              _stw_memory_manager;
563   GCMemoryManager              _cycle_memory_manager;
564   ConcurrentGCTimer*           _gc_timer;
565   SoftRefPolicy                _soft_ref_policy;
566 
567   // For exporting to SA
568   int                          _log_min_obj_alignment_in_bytes;
569 public:
570   ShenandoahMonitoringSupport* monitoring_support() const { return _monitoring_support;    }
571   GCMemoryManager* cycle_memory_manager()           { return &_cycle_memory_manager; }
572   GCMemoryManager* stw_memory_manager()             { return &_stw_memory_manager;   }
573   SoftRefPolicy* soft_ref_policy()                  { return &_soft_ref_policy;      }
574 
575   GrowableArray<GCMemoryManager*> memory_managers();
576   GrowableArray<MemoryPool*> memory_pools();
577   MemoryUsage memory_usage();
578   GCTracer* tracer();
579   ConcurrentGCTimer* gc_timer() const;
580 








581 // ---------- Class Unloading
582 //
583 private:
584   ShenandoahSharedFlag  _is_aging_cycle;
585   ShenandoahSharedFlag _unload_classes;
586   ShenandoahUnload     _unloader;
587 
588 public:
589   void set_unload_classes(bool uc);
590   bool unload_classes() const;
591 
592   // Perform STW class unloading and weak root cleaning
593   void parallel_cleaning(bool full_gc);
594 
595 private:
596   void stw_unload_classes(bool full_gc);
597   void stw_process_weak_roots(bool full_gc);
598   void stw_weak_refs(bool full_gc);
599 
600   // Heap iteration support
601   void scan_roots_for_iteration(ShenandoahScanObjectStack* oop_stack, ObjectIterateScanRootClosure* oops);
602   bool prepare_aux_bitmap_for_iteration();
603   void reclaim_aux_bitmap_for_iteration();
604 
605 // ---------- Generic interface hooks
606 // Minor things that super-interface expects us to implement to play nice with
607 // the rest of runtime. Some of the things here are not required to be implemented,
608 // and can be stubbed out.
609 //
610 public:
611   AdaptiveSizePolicy* size_policy() shenandoah_not_implemented_return(NULL);
612   bool is_maximal_no_gc() const shenandoah_not_implemented_return(false);
613 
614   bool is_in(const void* p) const;
615 
616   bool is_in_active_generation(oop obj) const;
617   bool is_in_young(const void* p) const;
618   bool is_in_old(const void* p) const;
619   inline bool is_old(oop pobj) const;
620 
621   bool requires_barriers(stackChunkOop obj) const;
622 
623   MemRegion reserved_region() const { return _reserved; }
624   bool is_in_reserved(const void* addr) const { return _reserved.contains(addr); }
625 
626   void collect(GCCause::Cause cause);
627   void do_full_collection(bool clear_all_soft_refs);
628 
629   // Used for parsing heap during error printing
630   HeapWord* block_start(const void* addr) const;
631   bool block_is_obj(const HeapWord* addr) const;
632   bool print_location(outputStream* st, void* addr) const;
633 
634   // Used for native heap walkers: heap dumpers, mostly
635   void object_iterate(ObjectClosure* cl);
636   // Parallel heap iteration support
637   virtual ParallelObjectIteratorImpl* parallel_object_iterator(uint workers);
638 
639   // Keep alive an object that was loaded with AS_NO_KEEPALIVE.
640   void keep_alive(oop obj);

656 // ---------- Pinning hooks
657 //
658 public:
659   // Shenandoah supports per-object (per-region) pinning
660   bool supports_object_pinning() const { return true; }
661 
662   oop pin_object(JavaThread* thread, oop obj);
663   void unpin_object(JavaThread* thread, oop obj);
664 
665   void sync_pinned_region_status();
666   void assert_pinned_region_status() NOT_DEBUG_RETURN;
667 
668 // ---------- Concurrent Stack Processing support
669 //
670 public:
671   bool uses_stack_watermark_barrier() const { return true; }
672 
673 // ---------- Allocation support
674 //
675 private:
676   HeapWord* allocate_memory_under_lock(ShenandoahAllocRequest& request, bool& in_new_region, bool is_promotion);
677 
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   inline HeapWord* allocate_from_plab(Thread* thread, size_t size, bool is_promotion);
683   HeapWord* allocate_from_plab_slow(Thread* thread, size_t size, bool is_promotion);
684   HeapWord* allocate_new_plab(size_t min_size, size_t word_size, size_t* actual_size);
685 
686 public:
687   HeapWord* allocate_memory(ShenandoahAllocRequest& request, bool is_promotion);
688   HeapWord* mem_allocate(size_t size, bool* what);
689   MetaWord* satisfy_failed_metadata_allocation(ClassLoaderData* loader_data,
690                                                size_t size,
691                                                Metaspace::MetadataType mdtype);
692 
693   void notify_mutator_alloc_words(size_t words, bool waste);
694 
695   HeapWord* allocate_new_tlab(size_t min_size, size_t requested_size, size_t* actual_size);
696   size_t tlab_capacity(Thread *thr) const;
697   size_t unsafe_max_tlab_alloc(Thread *thread) const;
698   size_t max_tlab_size() const;
699   size_t tlab_used(Thread* ignored) const;
700 
701   void ensure_parsability(bool retire_labs);
702 
703   void labs_make_parsable();
704   void tlabs_retire(bool resize);
705   void gclabs_retire(bool resize);
706 
707   void set_young_lab_region_flags();
708 
709 // ---------- Marking support
710 //
711 private:
712   ShenandoahMarkingContext* _marking_context;
713   MemRegion  _bitmap_region;
714   MemRegion  _aux_bitmap_region;
715   MarkBitMap _verification_bit_map;
716   MarkBitMap _aux_bit_map;
717 
718   size_t _bitmap_size;
719   size_t _bitmap_regions_per_slice;
720   size_t _bitmap_bytes_per_slice;
721 
722   size_t _pretouch_heap_page_size;
723   size_t _pretouch_bitmap_page_size;
724 
725   bool _bitmap_region_special;
726   bool _aux_bitmap_region_special;
727 
728   ShenandoahLiveData** _liveness_cache;
729 
730 public:
731   inline ShenandoahMarkingContext* complete_marking_context() const;
732   inline ShenandoahMarkingContext* marking_context() const;


733 
734   template<class T>
735   inline void marked_object_iterate(ShenandoahHeapRegion* region, T* cl);
736 
737   template<class T>
738   inline void marked_object_iterate(ShenandoahHeapRegion* region, T* cl, HeapWord* limit);
739 
740   template<class T>
741   inline void marked_object_oop_iterate(ShenandoahHeapRegion* region, T* cl, HeapWord* limit);
742 


743   // SATB barriers hooks
744   inline bool requires_marking(const void* entry) const;
745 
746   // Support for bitmap uncommits
747   bool commit_bitmap_slice(ShenandoahHeapRegion *r);
748   bool uncommit_bitmap_slice(ShenandoahHeapRegion *r);
749   bool is_bitmap_slice_committed(ShenandoahHeapRegion* r, bool skip_self = false);
750 
751   // Liveness caching support
752   ShenandoahLiveData* get_liveness_cache(uint worker_id);
753   void flush_liveness_cache(uint worker_id);
754 
755   size_t pretouch_heap_page_size() { return _pretouch_heap_page_size; }
756 
757 // ---------- Evacuation support
758 //
759 private:
760   ShenandoahCollectionSet* _collection_set;
761   ShenandoahEvacOOMHandler _oom_evac_handler;
762   ShenandoahSharedFlag _old_gen_oom_evac;
763 
764   inline oop try_evacuate_object(oop src, Thread* thread, ShenandoahHeapRegion* from_region, ShenandoahRegionAffiliation target_gen);
765   void handle_old_evacuation(HeapWord* obj, size_t words, bool promotion);
766   void handle_old_evacuation_failure();
767   void handle_promotion_failure();
768 
769 public:
770   static address in_cset_fast_test_addr();
771 
772   ShenandoahCollectionSet* collection_set() const { return _collection_set; }
773 
774   // Checks if object is in the collection set.
775   inline bool in_collection_set(oop obj) const;
776 
777   // Checks if location is in the collection set. Can be interior pointer, not the oop itself.
778   inline bool in_collection_set_loc(void* loc) const;
779 
780   // Evacuates or promotes object src. Returns the evacuated object, either evacuated
781   // by this thread, or by some other thread.
782   inline oop evacuate_object(oop src, Thread* thread);
783 
784   // Call before/after evacuation.
785   inline void enter_evacuation(Thread* t);
786   inline void leave_evacuation(Thread* t);
787 
788   inline bool clear_old_evacuation_failure();
789 
790 // ---------- Generational support
791 //
792 private:
793   RememberedScanner* _card_scan;
794 
795 public:
796   inline RememberedScanner* card_scan() { return _card_scan; }
797   void clear_cards_for(ShenandoahHeapRegion* region);
798   void dirty_cards(HeapWord* start, HeapWord* end);
799   void clear_cards(HeapWord* start, HeapWord* end);
800   void mark_card_as_dirty(void* location);
801   void retire_plab(PLAB* plab);
802   void retire_plab(PLAB* plab, Thread* thread);
803   void cancel_old_gc();
804   bool is_old_gc_active();
805   void coalesce_and_fill_old_regions();
806 
807 // ---------- Helper functions
808 //
809 public:
810   template <class T>
811   inline void conc_update_with_forwarded(T* p);
812 
813   template <class T>
814   inline void update_with_forwarded(T* p);
815 
816   static inline void atomic_update_oop(oop update,       oop* addr,       oop compare);
817   static inline void atomic_update_oop(oop update, narrowOop* addr,       oop compare);
818   static inline void atomic_update_oop(oop update, narrowOop* addr, narrowOop compare);
819 
820   static inline bool atomic_update_oop_check(oop update,       oop* addr,       oop compare);
821   static inline bool atomic_update_oop_check(oop update, narrowOop* addr,       oop compare);
822   static inline bool atomic_update_oop_check(oop update, narrowOop* addr, narrowOop compare);
823 
824   static inline void atomic_clear_oop(      oop* addr,       oop compare);
825   static inline void atomic_clear_oop(narrowOop* addr,       oop compare);
826   static inline void atomic_clear_oop(narrowOop* addr, narrowOop compare);
827 
828   size_t trash_humongous_region_at(ShenandoahHeapRegion *r);
829 
830   static inline void increase_object_age(oop obj, uint additional_age);
831 
832   void transfer_old_pointers_from_satb();
833 private:
834   void trash_cset_regions();
835 
836 // ---------- Testing helpers functions
837 //
838 private:
839   ShenandoahSharedFlag _inject_alloc_failure;
840 
841   void try_inject_alloc_failure();
842   bool should_inject_alloc_failure();
843 };
844 
845 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHHEAP_HPP
< prev index next >