< prev index next >

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

Print this page

  1 /*
  2  * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
  3  * Copyright (c) 2013, 2021, Red Hat, Inc. All rights reserved.

  4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5  *
  6  * This code is free software; you can redistribute it and/or modify it
  7  * under the terms of the GNU General Public License version 2 only, as
  8  * published by the Free Software Foundation.
  9  *
 10  * This code is distributed in the hope that it will be useful, but WITHOUT
 11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 13  * version 2 for more details (a copy is included in the LICENSE file that
 14  * accompanied this code).
 15  *
 16  * You should have received a copy of the GNU General Public License version
 17  * 2 along with this work; if not, write to the Free Software Foundation,
 18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 19  *
 20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 21  * or visit www.oracle.com if you need additional information or have any
 22  * questions.
 23  *
 24  */
 25 
 26 #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHHEAP_HPP
 27 #define SHARE_GC_SHENANDOAH_SHENANDOAHHEAP_HPP
 28 

 29 #include "gc/shared/markBitMap.hpp"
 30 #include "gc/shared/softRefPolicy.hpp"
 31 #include "gc/shared/collectedHeap.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 "memory/metaspace.hpp"
 40 #include "services/memoryManager.hpp"
 41 #include "utilities/globalDefinitions.hpp"
 42 #include "utilities/stack.hpp"
 43 
 44 class ConcurrentGCTimer;
 45 class ObjectIterateScanRootClosure;

 46 class ShenandoahCollectorPolicy;
 47 class ShenandoahControlThread;
 48 class ShenandoahGCSession;
 49 class ShenandoahGCStateResetter;



 50 class ShenandoahHeuristics;


 51 class ShenandoahMarkingContext;
 52 class ShenandoahMode;
 53 class ShenandoahPhaseTimings;
 54 class ShenandoahHeap;
 55 class ShenandoahHeapRegion;
 56 class ShenandoahHeapRegionClosure;
 57 class ShenandoahCollectionSet;
 58 class ShenandoahFreeSet;
 59 class ShenandoahConcurrentMark;
 60 class ShenandoahFullGC;
 61 class ShenandoahMonitoringSupport;

 62 class ShenandoahPacer;
 63 class ShenandoahReferenceProcessor;
 64 class ShenandoahVerifier;
 65 class ShenandoahWorkerThreads;
 66 class VMStructs;
 67 
 68 // Used for buffering per-region liveness data.
 69 // Needed since ShenandoahHeapRegion uses atomics to update liveness.
 70 // The ShenandoahHeap array has max-workers elements, each of which is an array of
 71 // uint16_t * max_regions. The choice of uint16_t is not accidental:
 72 // there is a tradeoff between static/dynamic footprint that translates
 73 // into cache pressure (which is already high during marking), and
 74 // too many atomic updates. uint32_t is too large, uint8_t is too small.
 75 typedef uint16_t ShenandoahLiveData;
 76 #define SHENANDOAH_LIVEDATA_MAX ((ShenandoahLiveData)-1)
 77 
 78 class ShenandoahRegionIterator : public StackObj {
 79 private:
 80   ShenandoahHeap* _heap;
 81 

106 public:
107   virtual void heap_region_do(ShenandoahHeapRegion* r) = 0;
108   virtual bool is_thread_safe() { return false; }
109 };
110 
111 typedef ShenandoahLock    ShenandoahHeapLock;
112 typedef ShenandoahLocker  ShenandoahHeapLocker;
113 typedef Stack<oop, mtGC>  ShenandoahScanObjectStack;
114 
115 // Shenandoah GC is low-pause concurrent GC that uses Brooks forwarding pointers
116 // to encode forwarding data. See BrooksPointer for details on forwarding data encoding.
117 // See ShenandoahControlThread for GC cycle structure.
118 //
119 class ShenandoahHeap : public CollectedHeap {
120   friend class ShenandoahAsserts;
121   friend class VMStructs;
122   friend class ShenandoahGCSession;
123   friend class ShenandoahGCStateResetter;
124   friend class ShenandoahParallelObjectIterator;
125   friend class ShenandoahSafepoint;

126   // Supported GC
127   friend class ShenandoahConcurrentGC;

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

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











142 // ---------- Initialization, termination, identification, printing routines
143 //
144 public:
145   static ShenandoahHeap* heap();
146 
147   const char* name()          const override { return "Shenandoah"; }
148   ShenandoahHeap::Name kind() const override { return CollectedHeap::Shenandoah; }
149 
150   ShenandoahHeap(ShenandoahCollectorPolicy* policy);
151   jint initialize() override;
152   void post_initialize() override;
153   void initialize_mode();
154   void initialize_heuristics();
155 
156   void initialize_serviceability() override;
157 
158   void print_on(outputStream* st)              const override;
159   void print_extended_on(outputStream *st)     const override;
160   void print_tracing_info()                    const override;
161   void print_heap_regions_on(outputStream* st) const;
162 
163   void stop() override;
164 
165   void prepare_for_verify() override;
166   void verify(VerifyOption vo) override;
167 
168 // WhiteBox testing support.
169   bool supports_concurrent_gc_breakpoints() const override {
170     return true;
171   }
172 
173 // ---------- Heap counters and metrics
174 //
175 private:
176            size_t _initial_size;
177            size_t _minimum_size;

178   volatile size_t _soft_max_size;
179   shenandoah_padding(0);
180   volatile size_t _used;
181   volatile size_t _committed;
182   volatile size_t _bytes_allocated_since_gc_start;
183   shenandoah_padding(1);
184 


185 public:
186   void increase_used(size_t bytes);
187   void decrease_used(size_t bytes);
188   void set_used(size_t bytes);

189 
190   void increase_committed(size_t bytes);
191   void decrease_committed(size_t bytes);
192   void increase_allocated(size_t bytes);
193 
194   size_t bytes_allocated_since_gc_start();
195   void reset_bytes_allocated_since_gc_start();
196 
197   size_t min_capacity()      const;
198   size_t max_capacity()      const override;
199   size_t soft_max_capacity() const;
200   size_t initial_capacity()  const;
201   size_t capacity()          const override;
202   size_t used()              const override;
203   size_t committed()         const;
204 
205   void set_soft_max_capacity(size_t v);
206 









207 // ---------- Workers handling
208 //
209 private:
210   uint _max_workers;
211   ShenandoahWorkerThreads* _workers;
212   ShenandoahWorkerThreads* _safepoint_workers;
213 


214 public:
215   uint max_workers();
216   void assert_gc_workers(uint nworker) NOT_DEBUG_RETURN;
217 
218   WorkerThreads* workers() const;
219   WorkerThreads* safepoint_workers() override;
220 
221   void gc_threads_do(ThreadClosure* tcl) const override;
222 
223 // ---------- Heap regions handling machinery
224 //
225 private:
226   MemRegion _heap_region;
227   bool      _heap_region_special;
228   size_t    _num_regions;
229   ShenandoahHeapRegion** _regions;
230   ShenandoahRegionIterator _update_refs_iterator;
231 
232 public:
233 
234   inline HeapWord* base() const { return _heap_region.start(); }
235 
236   inline size_t num_regions() const { return _num_regions; }
237   inline bool is_heap_region_special() { return _heap_region_special; }
238 
239   inline ShenandoahHeapRegion* const heap_region_containing(const void* addr) const;
240   inline size_t heap_region_index_containing(const void* addr) const;
241 
242   inline ShenandoahHeapRegion* const get_region(size_t region_idx) const;
243 
244   void heap_region_iterate(ShenandoahHeapRegionClosure* blk) const;
245   void parallel_heap_region_iterate(ShenandoahHeapRegionClosure* blk) const;
246 


247 // ---------- GC state machinery
248 //
249 // GC state describes the important parts of collector state, that may be
250 // used to make barrier selection decisions in the native and generated code.
251 // Multiple bits can be set at once.
252 //
253 // Important invariant: when GC state is zero, the heap is stable, and no barriers
254 // are required.
255 //
256 public:
257   enum GCStateBitPos {
258     // Heap has forwarded objects: needs LRB barriers.
259     HAS_FORWARDED_BITPOS   = 0,
260 
261     // Heap is under marking: needs SATB barriers.

262     MARKING_BITPOS    = 1,
263 
264     // Heap is under evacuation: needs LRB barriers. (Set together with HAS_FORWARDED)
265     EVACUATION_BITPOS = 2,
266 
267     // Heap is under updating: needs no additional barriers.
268     UPDATEREFS_BITPOS = 3,
269 
270     // Heap is under weak-reference/roots processing: needs weak-LRB barriers.
271     WEAK_ROOTS_BITPOS  = 4,






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


281   };
282 
283 private:
284   bool _gc_state_changed;
285   ShenandoahSharedBitmap _gc_state;

286   ShenandoahSharedFlag   _degenerated_gc_in_progress;
287   ShenandoahSharedFlag   _full_gc_in_progress;
288   ShenandoahSharedFlag   _full_gc_move_in_progress;
289   ShenandoahSharedFlag   _progress_last_gc;
290   ShenandoahSharedFlag   _concurrent_strong_root_in_progress;
291 


292   // This updates the singlular, global gc state. This must happen on a safepoint.
293   void set_gc_state(uint mask, bool value);
294 


295 public:
296   char gc_state() const;
297 
298   // This copies the global gc state into a thread local variable for java threads.
299   // It is primarily intended to support quick access at barriers.
300   void propagate_gc_state_to_java_threads();
301 
302   // This is public to support assertions that the state hasn't been changed off of
303   // a safepoint and that any changes were propagated to java threads after the safepoint.
304   bool has_gc_state_changed() const { return _gc_state_changed; }
305 
306   void set_concurrent_mark_in_progress(bool in_progress);







307   void set_evacuation_in_progress(bool in_progress);
308   void set_update_refs_in_progress(bool in_progress);
309   void set_degenerated_gc_in_progress(bool in_progress);
310   void set_full_gc_in_progress(bool in_progress);
311   void set_full_gc_move_in_progress(bool in_progress);
312   void set_has_forwarded_objects(bool cond);
313   void set_concurrent_strong_root_in_progress(bool cond);
314   void set_concurrent_weak_root_in_progress(bool cond);
315 
316   inline bool is_stable() const;
317   inline bool is_idle() const;

318   inline bool is_concurrent_mark_in_progress() const;


319   inline bool is_update_refs_in_progress() const;
320   inline bool is_evacuation_in_progress() const;
321   inline bool is_degenerated_gc_in_progress() const;
322   inline bool is_full_gc_in_progress() const;
323   inline bool is_full_gc_move_in_progress() const;
324   inline bool has_forwarded_objects() const;
325 
326   inline bool is_stw_gc_in_progress() const;
327   inline bool is_concurrent_strong_root_in_progress() const;
328   inline bool is_concurrent_weak_root_in_progress() const;




329 
330 private:


331   enum CancelState {
332     // Normal state. GC has not been cancelled and is open for cancellation.
333     // Worker threads can suspend for safepoint.
334     CANCELLABLE,
335 
336     // GC has been cancelled. Worker threads can not suspend for
337     // safepoint but must finish their work as soon as possible.
338     CANCELLED
339   };
340 

341   ShenandoahSharedEnumFlag<CancelState> _cancelled_gc;





342   bool try_cancel_gc();
343 
344 public:
345 
346   inline bool cancelled_gc() const;
347   inline bool check_cancelled_gc_and_yield(bool sts_active = true);
348 
349   inline void clear_cancelled_gc();
350 

351   void cancel_gc(GCCause::Cause cause);
352 
353 public:
354   // Elastic heap support
355   void entry_uncommit(double shrink_before, size_t shrink_until);

356   void op_uncommit(double shrink_before, size_t shrink_until);
357 



358 private:
359   // GC support
360   // Reset bitmap, prepare regions for new GC cycle
361   void prepare_gc();
362   void prepare_regions_and_collection_set(bool concurrent);
363   // Evacuation
364   void evacuate_collection_set(bool concurrent);
365   // Concurrent root processing
366   void prepare_concurrent_roots();
367   void finish_concurrent_roots();
368   // Concurrent class unloading support
369   void do_class_unloading();
370   // Reference updating
371   void prepare_update_heap_references(bool concurrent);
372   void update_heap_references(bool concurrent);
373   // Final update region states
374   void update_heap_region_states(bool concurrent);
375   void rebuild_free_set(bool concurrent);
376 
377   void rendezvous_threads();
378   void recycle_trash();
379 public:
380   void notify_gc_progress()    { _progress_last_gc.set();   }
381   void notify_gc_no_progress() { _progress_last_gc.unset(); }


382 
383 //
384 // Mark support
385 private:
386   ShenandoahControlThread*   _control_thread;







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

397 
398 public:








399   ShenandoahCollectorPolicy* shenandoah_policy() const { return _shenandoah_policy; }
400   ShenandoahMode*            mode()              const { return _gc_mode;           }
401   ShenandoahHeuristics*      heuristics()        const { return _heuristics;        }
402   ShenandoahFreeSet*         free_set()          const { return _free_set;          }
403   ShenandoahPacer*           pacer()             const { return _pacer;             }
404 
405   ShenandoahPhaseTimings*    phase_timings()     const { return _phase_timings;     }






406 
407   ShenandoahVerifier*        verifier();
408 
409 // ---------- VM subsystem bindings
410 //
411 private:
412   ShenandoahMonitoringSupport* _monitoring_support;
413   MemoryPool*                  _memory_pool;
414   GCMemoryManager              _stw_memory_manager;
415   GCMemoryManager              _cycle_memory_manager;
416   ConcurrentGCTimer*           _gc_timer;
417   SoftRefPolicy                _soft_ref_policy;
418 
419   // For exporting to SA
420   int                          _log_min_obj_alignment_in_bytes;
421 public:
422   ShenandoahMonitoringSupport* monitoring_support()          { return _monitoring_support;    }
423   GCMemoryManager* cycle_memory_manager()                    { return &_cycle_memory_manager; }
424   GCMemoryManager* stw_memory_manager()                      { return &_stw_memory_manager;   }
425   SoftRefPolicy* soft_ref_policy()                  override { return &_soft_ref_policy;      }
426 
427   GrowableArray<GCMemoryManager*> memory_managers() override;
428   GrowableArray<MemoryPool*> memory_pools() override;
429   MemoryUsage memory_usage() override;
430   GCTracer* tracer();
431   ConcurrentGCTimer* gc_timer() const;
432 
433 // ---------- Reference processing
434 //
435 private:
436   ShenandoahReferenceProcessor* const _ref_processor;
437 
438 public:
439   ShenandoahReferenceProcessor* ref_processor() { return _ref_processor; }
440 
441 // ---------- Class Unloading
442 //
443 private:
444   ShenandoahSharedFlag _unload_classes;
445   ShenandoahUnload     _unloader;
446 
447 public:
448   void set_unload_classes(bool uc);
449   bool unload_classes() const;
450 
451   // Perform STW class unloading and weak root cleaning
452   void parallel_cleaning(bool full_gc);
453 
454 private:
455   void stw_unload_classes(bool full_gc);
456   void stw_process_weak_roots(bool full_gc);
457   void stw_weak_refs(bool full_gc);
458 



459   // Heap iteration support
460   void scan_roots_for_iteration(ShenandoahScanObjectStack* oop_stack, ObjectIterateScanRootClosure* oops);
461   bool prepare_aux_bitmap_for_iteration();
462   void reclaim_aux_bitmap_for_iteration();
463 
464 // ---------- Generic interface hooks
465 // Minor things that super-interface expects us to implement to play nice with
466 // the rest of runtime. Some of the things here are not required to be implemented,
467 // and can be stubbed out.
468 //
469 public:
470   bool is_maximal_no_gc() const override shenandoah_not_implemented_return(false);
471 
472   bool is_in(const void* p) const override;










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

505   void unregister_nmethod(nmethod* nm) override;
506   void verify_nmethod(nmethod* nm) override {}
507 
508 // ---------- Pinning hooks
509 //
510 public:
511   // Shenandoah supports per-object (per-region) pinning
512   void pin_object(JavaThread* thread, oop obj) override;
513   void unpin_object(JavaThread* thread, oop obj) override;
514 
515   void sync_pinned_region_status();
516   void assert_pinned_region_status() NOT_DEBUG_RETURN;
517 
518 // ---------- Concurrent Stack Processing support
519 //
520 public:
521   bool uses_stack_watermark_barrier() const override { return true; }
522 
523 // ---------- Allocation support
524 //



525 private:
526   HeapWord* allocate_memory_under_lock(ShenandoahAllocRequest& request, bool& in_new_region);
527   inline HeapWord* allocate_from_gclab(Thread* thread, size_t size);
528   HeapWord* allocate_from_gclab_slow(Thread* thread, size_t size);
529   HeapWord* allocate_new_gclab(size_t min_size, size_t word_size, size_t* actual_size);
530 
531 public:
532   HeapWord* allocate_memory(ShenandoahAllocRequest& request);
533   HeapWord* mem_allocate(size_t size, bool* what) override;
534   MetaWord* satisfy_failed_metadata_allocation(ClassLoaderData* loader_data,
535                                                size_t size,
536                                                Metaspace::MetadataType mdtype) override;
537 
538   void notify_mutator_alloc_words(size_t words, bool waste);
539 
540   HeapWord* allocate_new_tlab(size_t min_size, size_t requested_size, size_t* actual_size) override;
541   size_t tlab_capacity(Thread *thr) const override;
542   size_t unsafe_max_tlab_alloc(Thread *thread) const override;
543   size_t max_tlab_size() const override;
544   size_t tlab_used(Thread* ignored) const override;
545 
546   void ensure_parsability(bool retire_labs) override;
547 
548   void labs_make_parsable();
549   void tlabs_retire(bool resize);
550   void gclabs_retire(bool resize);
551 
552 // ---------- Marking support
553 //
554 private:
555   ShenandoahMarkingContext* _marking_context;
556   MemRegion  _bitmap_region;
557   MemRegion  _aux_bitmap_region;
558   MarkBitMap _verification_bit_map;
559   MarkBitMap _aux_bit_map;
560 
561   size_t _bitmap_size;
562   size_t _bitmap_regions_per_slice;
563   size_t _bitmap_bytes_per_slice;
564 
565   size_t _pretouch_heap_page_size;
566   size_t _pretouch_bitmap_page_size;
567 
568   bool _bitmap_region_special;
569   bool _aux_bitmap_region_special;
570 
571   ShenandoahLiveData** _liveness_cache;
572 
573 public:
574   inline ShenandoahMarkingContext* complete_marking_context() const;
575   inline ShenandoahMarkingContext* marking_context() const;
576   inline void mark_complete_marking_context();
577   inline void mark_incomplete_marking_context();
578 
579   template<class T>
580   inline void marked_object_iterate(ShenandoahHeapRegion* region, T* cl);
581 
582   template<class T>
583   inline void marked_object_iterate(ShenandoahHeapRegion* region, T* cl, HeapWord* limit);
584 
585   template<class T>
586   inline void marked_object_oop_iterate(ShenandoahHeapRegion* region, T* cl, HeapWord* limit);
587 
588   void reset_mark_bitmap();
589 
590   // SATB barriers hooks
591   inline bool requires_marking(const void* entry) const;
592 
593   // Support for bitmap uncommits
594   bool commit_bitmap_slice(ShenandoahHeapRegion *r);
595   bool uncommit_bitmap_slice(ShenandoahHeapRegion *r);
596   bool is_bitmap_slice_committed(ShenandoahHeapRegion* r, bool skip_self = false);
597 
598   // Liveness caching support
599   ShenandoahLiveData* get_liveness_cache(uint worker_id);
600   void flush_liveness_cache(uint worker_id);
601 
602   size_t pretouch_heap_page_size() { return _pretouch_heap_page_size; }
603 
604 // ---------- Evacuation support
605 //
606 private:
607   ShenandoahCollectionSet* _collection_set;
608   ShenandoahEvacOOMHandler _oom_evac_handler;
609 

610 public:

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










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









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

  1 /*
  2  * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
  3  * Copyright (c) 2013, 2021, Red Hat, Inc. All rights reserved.
  4  * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
  5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  6  *
  7  * This code is free software; you can redistribute it and/or modify it
  8  * under the terms of the GNU General Public License version 2 only, as
  9  * published by the Free Software Foundation.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any
 23  * questions.
 24  *
 25  */
 26 
 27 #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHHEAP_HPP
 28 #define SHARE_GC_SHENANDOAH_SHENANDOAHHEAP_HPP
 29 
 30 #include "gc/shared/ageTable.hpp"
 31 #include "gc/shared/markBitMap.hpp"
 32 #include "gc/shared/softRefPolicy.hpp"
 33 #include "gc/shared/collectedHeap.hpp"
 34 #include "gc/shenandoah/shenandoahAgeCensus.hpp"
 35 #include "gc/shenandoah/heuristics/shenandoahSpaceInfo.hpp"
 36 #include "gc/shenandoah/shenandoahAsserts.hpp"
 37 #include "gc/shenandoah/shenandoahAllocRequest.hpp"
 38 #include "gc/shenandoah/shenandoahAsserts.hpp"
 39 #include "gc/shenandoah/shenandoahController.hpp"
 40 #include "gc/shenandoah/shenandoahLock.hpp"
 41 #include "gc/shenandoah/shenandoahEvacOOMHandler.hpp"
 42 #include "gc/shenandoah/shenandoahEvacTracker.hpp"
 43 #include "gc/shenandoah/shenandoahGenerationType.hpp"
 44 #include "gc/shenandoah/shenandoahMmuTracker.hpp"
 45 #include "gc/shenandoah/shenandoahPadding.hpp"
 46 #include "gc/shenandoah/shenandoahScanRemembered.hpp"
 47 #include "gc/shenandoah/shenandoahSharedVariables.hpp"
 48 #include "gc/shenandoah/shenandoahUnload.hpp"
 49 #include "memory/metaspace.hpp"
 50 #include "services/memoryManager.hpp"
 51 #include "utilities/globalDefinitions.hpp"
 52 #include "utilities/stack.hpp"
 53 
 54 class ConcurrentGCTimer;
 55 class ObjectIterateScanRootClosure;
 56 class PLAB;
 57 class ShenandoahCollectorPolicy;
 58 class ShenandoahRegulatorThread;
 59 class ShenandoahGCSession;
 60 class ShenandoahGCStateResetter;
 61 class ShenandoahGeneration;
 62 class ShenandoahYoungGeneration;
 63 class ShenandoahOldGeneration;
 64 class ShenandoahHeuristics;
 65 class ShenandoahOldHeuristics;
 66 class ShenandoahYoungHeuristics;
 67 class ShenandoahMarkingContext;

 68 class ShenandoahPhaseTimings;
 69 class ShenandoahHeap;
 70 class ShenandoahHeapRegion;
 71 class ShenandoahHeapRegionClosure;
 72 class ShenandoahCollectionSet;
 73 class ShenandoahFreeSet;
 74 class ShenandoahConcurrentMark;
 75 class ShenandoahFullGC;
 76 class ShenandoahMonitoringSupport;
 77 class ShenandoahMode;
 78 class ShenandoahPacer;
 79 class ShenandoahReferenceProcessor;
 80 class ShenandoahVerifier;
 81 class ShenandoahWorkerThreads;
 82 class VMStructs;
 83 
 84 // Used for buffering per-region liveness data.
 85 // Needed since ShenandoahHeapRegion uses atomics to update liveness.
 86 // The ShenandoahHeap array has max-workers elements, each of which is an array of
 87 // uint16_t * max_regions. The choice of uint16_t is not accidental:
 88 // there is a tradeoff between static/dynamic footprint that translates
 89 // into cache pressure (which is already high during marking), and
 90 // too many atomic updates. uint32_t is too large, uint8_t is too small.
 91 typedef uint16_t ShenandoahLiveData;
 92 #define SHENANDOAH_LIVEDATA_MAX ((ShenandoahLiveData)-1)
 93 
 94 class ShenandoahRegionIterator : public StackObj {
 95 private:
 96   ShenandoahHeap* _heap;
 97 

122 public:
123   virtual void heap_region_do(ShenandoahHeapRegion* r) = 0;
124   virtual bool is_thread_safe() { return false; }
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 
143   // Supported GC
144   friend class ShenandoahConcurrentGC;
145   friend class ShenandoahOldGC;
146   friend class ShenandoahDegenGC;
147   friend class ShenandoahFullGC;
148   friend class ShenandoahUnload;
149 
150 // ---------- Locks that guard important data structures in Heap
151 //
152 private:
153   ShenandoahHeapLock _lock;
154   ShenandoahGeneration* _gc_generation;
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   ShenandoahHeuristics* heuristics();
171 
172 // ---------- Initialization, termination, identification, printing routines
173 //
174 public:
175   static ShenandoahHeap* heap();
176 
177   const char* name()          const override { return "Shenandoah"; }
178   ShenandoahHeap::Name kind() const override { return CollectedHeap::Shenandoah; }
179 
180   ShenandoahHeap(ShenandoahCollectorPolicy* policy);
181   jint initialize() override;
182   void post_initialize() override;
183   void initialize_heuristics_generations();
184   virtual void print_init_logger() const;

185   void initialize_serviceability() override;
186 
187   void print_on(outputStream* st)              const override;
188   void print_extended_on(outputStream *st)     const override;
189   void print_tracing_info()                    const override;
190   void print_heap_regions_on(outputStream* st) const;
191 
192   void stop() override;
193 
194   void prepare_for_verify() override;
195   void verify(VerifyOption vo) override;
196 
197 // WhiteBox testing support.
198   bool supports_concurrent_gc_breakpoints() const override {
199     return true;
200   }
201 
202 // ---------- Heap counters and metrics
203 //
204 private:
205   size_t _initial_size;
206   size_t _minimum_size;
207 
208   volatile size_t _soft_max_size;
209   shenandoah_padding(0);

210   volatile size_t _committed;

211   shenandoah_padding(1);
212 
213   void increase_used(const ShenandoahAllocRequest& req);
214 
215 public:
216   void increase_used(ShenandoahGeneration* generation, size_t bytes);
217   void decrease_used(ShenandoahGeneration* generation, size_t bytes);
218   void increase_humongous_waste(ShenandoahGeneration* generation, size_t bytes);
219   void decrease_humongous_waste(ShenandoahGeneration* generation, size_t bytes);
220 
221   void increase_committed(size_t bytes);
222   void decrease_committed(size_t bytes);

223 

224   void reset_bytes_allocated_since_gc_start();
225 
226   size_t min_capacity()      const;
227   size_t max_capacity()      const override;
228   size_t soft_max_capacity() const;
229   size_t initial_capacity()  const;
230   size_t capacity()          const override;
231   size_t used()              const override;
232   size_t committed()         const;
233 
234   void set_soft_max_capacity(size_t v);
235 
236 // ---------- Periodic Tasks
237 //
238 private:
239   void notify_heap_changed();
240 
241 public:
242   void set_forced_counters_update(bool value);
243   void handle_force_counters_update();
244 
245 // ---------- Workers handling
246 //
247 private:
248   uint _max_workers;
249   ShenandoahWorkerThreads* _workers;
250   ShenandoahWorkerThreads* _safepoint_workers;
251 
252   virtual void initialize_controller();
253 
254 public:
255   uint max_workers();
256   void assert_gc_workers(uint nworker) NOT_DEBUG_RETURN;
257 
258   WorkerThreads* workers() const;
259   WorkerThreads* safepoint_workers() override;
260 
261   void gc_threads_do(ThreadClosure* tcl) const override;
262 
263 // ---------- Heap regions handling machinery
264 //
265 private:
266   MemRegion _heap_region;
267   bool      _heap_region_special;
268   size_t    _num_regions;
269   ShenandoahHeapRegion** _regions;
270   uint8_t* _affiliations;       // Holds array of enum ShenandoahAffiliation, including FREE status in non-generational mode
271 
272 public:
273 
274   inline HeapWord* base() const { return _heap_region.start(); }
275 
276   inline size_t num_regions() const { return _num_regions; }
277   inline bool is_heap_region_special() { return _heap_region_special; }
278 
279   inline ShenandoahHeapRegion* heap_region_containing(const void* addr) const;
280   inline size_t heap_region_index_containing(const void* addr) const;
281 
282   inline ShenandoahHeapRegion* get_region(size_t region_idx) const;
283 
284   void heap_region_iterate(ShenandoahHeapRegionClosure* blk) const;
285   void parallel_heap_region_iterate(ShenandoahHeapRegionClosure* blk) const;
286 
287   inline ShenandoahMmuTracker* mmu_tracker() { return &_mmu_tracker; };
288 
289 // ---------- GC state machinery
290 //
291 // GC state describes the important parts of collector state, that may be
292 // used to make barrier selection decisions in the native and generated code.
293 // Multiple bits can be set at once.
294 //
295 // Important invariant: when GC state is zero, the heap is stable, and no barriers
296 // are required.
297 //
298 public:
299   enum GCStateBitPos {
300     // Heap has forwarded objects: needs LRB barriers.
301     HAS_FORWARDED_BITPOS   = 0,
302 
303     // Heap is under marking: needs SATB barriers.
304     // For generational mode, it means either young or old marking, or both.
305     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     // Young regions are under marking, need SATB barriers.
317     YOUNG_MARKING_BITPOS = 5,
318 
319     // Old regions are under marking, need SATB barriers.
320     OLD_MARKING_BITPOS = 6
321   };
322 
323   enum GCState {
324     STABLE        = 0,
325     HAS_FORWARDED = 1 << HAS_FORWARDED_BITPOS,
326     MARKING       = 1 << MARKING_BITPOS,
327     EVACUATION    = 1 << EVACUATION_BITPOS,
328     UPDATEREFS    = 1 << UPDATEREFS_BITPOS,
329     WEAK_ROOTS    = 1 << WEAK_ROOTS_BITPOS,
330     YOUNG_MARKING = 1 << YOUNG_MARKING_BITPOS,
331     OLD_MARKING   = 1 << OLD_MARKING_BITPOS
332   };
333 
334 private:
335   bool _gc_state_changed;
336   ShenandoahSharedBitmap _gc_state;
337   ShenandoahSharedFlag   _heap_changed;
338   ShenandoahSharedFlag   _degenerated_gc_in_progress;
339   ShenandoahSharedFlag   _full_gc_in_progress;
340   ShenandoahSharedFlag   _full_gc_move_in_progress;

341   ShenandoahSharedFlag   _concurrent_strong_root_in_progress;
342 
343   size_t _gc_no_progress_count;
344 
345   // This updates the singlular, global gc state. This must happen on a safepoint.
346   void set_gc_state(uint mask, bool value);
347 
348   ShenandoahAgeCensus* _age_census;    // Age census used for adapting tenuring threshold in generational mode
349 
350 public:
351   char gc_state() const;
352 
353   // This copies the global gc state into a thread local variable for java threads.
354   // It is primarily intended to support quick access at barriers.
355   void propagate_gc_state_to_java_threads();
356 
357   // This is public to support assertions that the state hasn't been changed off of
358   // a safepoint and that any changes were propagated to java threads after the safepoint.
359   bool has_gc_state_changed() const { return _gc_state_changed; }
360 
361   // Returns true if allocations have occurred in new regions or if regions have been
362   // uncommitted since the previous calls. This call will reset the flag to false.
363   bool has_changed() {
364     return _heap_changed.try_unset();
365   }
366 
367   void set_concurrent_young_mark_in_progress(bool in_progress);
368   void set_concurrent_old_mark_in_progress(bool in_progress);
369   void set_evacuation_in_progress(bool in_progress);
370   void set_update_refs_in_progress(bool in_progress);
371   void set_degenerated_gc_in_progress(bool in_progress);
372   void set_full_gc_in_progress(bool in_progress);
373   void set_full_gc_move_in_progress(bool in_progress);
374   void set_has_forwarded_objects(bool cond);
375   void set_concurrent_strong_root_in_progress(bool cond);
376   void set_concurrent_weak_root_in_progress(bool cond);
377 
378   inline bool is_stable() const;
379   inline bool is_idle() const;
380 
381   inline bool is_concurrent_mark_in_progress() const;
382   inline bool is_concurrent_young_mark_in_progress() const;
383   inline bool is_concurrent_old_mark_in_progress() const;
384   inline bool is_update_refs_in_progress() const;
385   inline bool is_evacuation_in_progress() const;
386   inline bool is_degenerated_gc_in_progress() const;
387   inline bool is_full_gc_in_progress() const;
388   inline bool is_full_gc_move_in_progress() const;
389   inline bool has_forwarded_objects() const;
390 
391   inline bool is_stw_gc_in_progress() const;
392   inline bool is_concurrent_strong_root_in_progress() const;
393   inline bool is_concurrent_weak_root_in_progress() const;
394   bool is_prepare_for_old_mark_in_progress() const;
395 
396   // Return the age census object for young gen (in generational mode)
397   inline ShenandoahAgeCensus* age_census() const;
398 
399 private:
400   void manage_satb_barrier(bool active);
401 
402   enum CancelState {
403     // Normal state. GC has not been cancelled and is open for cancellation.
404     // Worker threads can suspend for safepoint.
405     CANCELLABLE,
406 
407     // GC has been cancelled. Worker threads can not suspend for
408     // safepoint but must finish their work as soon as possible.
409     CANCELLED
410   };
411 
412   double _cancel_requested_time;
413   ShenandoahSharedEnumFlag<CancelState> _cancelled_gc;
414 
415   // Returns true if cancel request was successfully communicated.
416   // Returns false if some other thread already communicated cancel
417   // request.  A true return value does not mean GC has been
418   // cancelled, only that the process of cancelling GC has begun.
419   bool try_cancel_gc();
420 
421 public:

422   inline bool cancelled_gc() const;
423   inline bool check_cancelled_gc_and_yield(bool sts_active = true);
424 
425   inline void clear_cancelled_gc(bool clear_oom_handler = true);
426 
427   void cancel_concurrent_mark();
428   void cancel_gc(GCCause::Cause cause);
429 
430 public:
431   // These will uncommit empty regions if heap::committed > shrink_until
432   // and there exists at least one region which was made empty before shrink_before.
433   void maybe_uncommit(double shrink_before, size_t shrink_until);
434   void op_uncommit(double shrink_before, size_t shrink_until);
435 
436   // Returns true if the soft maximum heap has been changed using management APIs.
437   bool check_soft_max_changed();
438 
439 private:
440   // GC support



441   // Evacuation
442   void evacuate_collection_set(bool concurrent);
443   // Concurrent root processing
444   void prepare_concurrent_roots();
445   void finish_concurrent_roots();
446   // Concurrent class unloading support
447   void do_class_unloading();
448   // Reference updating
449   void prepare_update_heap_references(bool concurrent);
450   virtual void update_heap_references(bool concurrent);
451   // Final update region states
452   void update_heap_region_states(bool concurrent);

453 
454   void rendezvous_threads();
455   void recycle_trash();
456 public:
457   void rebuild_free_set(bool concurrent);
458   void notify_gc_progress();
459   void notify_gc_no_progress();
460   size_t get_gc_no_progress_count() const;
461 
462 //
463 // Mark support
464 private:
465   ShenandoahYoungGeneration* _young_generation;
466   ShenandoahGeneration*      _global_generation;
467   ShenandoahOldGeneration*   _old_generation;
468 
469 protected:
470   ShenandoahController*  _control_thread;
471 
472 private:
473   ShenandoahCollectorPolicy* _shenandoah_policy;
474   ShenandoahMode*            _gc_mode;

475   ShenandoahFreeSet*         _free_set;
476   ShenandoahPacer*           _pacer;
477   ShenandoahVerifier*        _verifier;
478 
479   ShenandoahPhaseTimings*       _phase_timings;
480   ShenandoahEvacuationTracker*  _evac_tracker;
481   ShenandoahMmuTracker          _mmu_tracker;
482   ShenandoahGenerationSizer     _generation_sizer;
483 
484 public:
485   ShenandoahController*   control_thread() { return _control_thread; }
486 
487   ShenandoahYoungGeneration* young_generation()  const { return _young_generation;  }
488   ShenandoahGeneration*      global_generation() const { return _global_generation; }
489   ShenandoahOldGeneration*   old_generation()    const { return _old_generation;    }
490   ShenandoahGeneration*      generation_for(ShenandoahAffiliation affiliation) const;
491   const ShenandoahGenerationSizer* generation_sizer()  const { return &_generation_sizer;  }
492 
493   ShenandoahCollectorPolicy* shenandoah_policy() const { return _shenandoah_policy; }
494   ShenandoahMode*            mode()              const { return _gc_mode;           }

495   ShenandoahFreeSet*         free_set()          const { return _free_set;          }
496   ShenandoahPacer*           pacer()             const { return _pacer;             }
497 
498   ShenandoahPhaseTimings*      phase_timings()   const { return _phase_timings;     }
499   ShenandoahEvacuationTracker* evac_tracker()    const { return _evac_tracker;      }
500 
501   ShenandoahEvacOOMHandler* oom_evac_handler() { return &_oom_evac_handler; }
502 
503   void on_cycle_start(GCCause::Cause cause, ShenandoahGeneration* generation);
504   void on_cycle_end(ShenandoahGeneration* generation);
505 
506   ShenandoahVerifier*        verifier();
507 
508 // ---------- VM subsystem bindings
509 //
510 private:
511   ShenandoahMonitoringSupport* _monitoring_support;
512   MemoryPool*                  _memory_pool;
513   GCMemoryManager              _stw_memory_manager;
514   GCMemoryManager              _cycle_memory_manager;
515   ConcurrentGCTimer*           _gc_timer;
516   SoftRefPolicy                _soft_ref_policy;
517 
518   // For exporting to SA
519   int                          _log_min_obj_alignment_in_bytes;
520 public:
521   ShenandoahMonitoringSupport* monitoring_support() const    { return _monitoring_support;    }
522   GCMemoryManager* cycle_memory_manager()                    { return &_cycle_memory_manager; }
523   GCMemoryManager* stw_memory_manager()                      { return &_stw_memory_manager;   }
524   SoftRefPolicy* soft_ref_policy()                  override { return &_soft_ref_policy;      }
525 
526   GrowableArray<GCMemoryManager*> memory_managers() override;
527   GrowableArray<MemoryPool*> memory_pools() override;
528   MemoryUsage memory_usage() override;
529   GCTracer* tracer();
530   ConcurrentGCTimer* gc_timer() const;
531 








532 // ---------- Class Unloading
533 //
534 private:
535   ShenandoahSharedFlag _unload_classes;
536   ShenandoahUnload     _unloader;
537 
538 public:
539   void set_unload_classes(bool uc);
540   bool unload_classes() const;
541 
542   // Perform STW class unloading and weak root cleaning
543   void parallel_cleaning(bool full_gc);
544 
545 private:
546   void stw_unload_classes(bool full_gc);
547   void stw_process_weak_roots(bool full_gc);
548   void stw_weak_refs(bool full_gc);
549 
550   inline void assert_lock_for_affiliation(ShenandoahAffiliation orig_affiliation,
551                                           ShenandoahAffiliation new_affiliation);
552 
553   // Heap iteration support
554   void scan_roots_for_iteration(ShenandoahScanObjectStack* oop_stack, ObjectIterateScanRootClosure* oops);
555   bool prepare_aux_bitmap_for_iteration();
556   void reclaim_aux_bitmap_for_iteration();
557 
558 // ---------- Generic interface hooks
559 // Minor things that super-interface expects us to implement to play nice with
560 // the rest of runtime. Some of the things here are not required to be implemented,
561 // and can be stubbed out.
562 //
563 public:
564   bool is_maximal_no_gc() const override shenandoah_not_implemented_return(false);
565 
566   inline bool is_in(const void* p) const override;
567 
568   inline bool is_in_active_generation(oop obj) const;
569   inline bool is_in_young(const void* p) const;
570   inline bool is_in_old(const void* p) const;
571   inline bool is_old(oop pobj) const;
572 
573   inline ShenandoahAffiliation region_affiliation(const ShenandoahHeapRegion* r);
574   inline void set_affiliation(ShenandoahHeapRegion* r, ShenandoahAffiliation new_affiliation);
575 
576   inline ShenandoahAffiliation region_affiliation(size_t index);
577 
578   bool requires_barriers(stackChunkOop obj) const override;
579 
580   MemRegion reserved_region() const { return _reserved; }
581   bool is_in_reserved(const void* addr) const { return _reserved.contains(addr); }
582 
583   void collect(GCCause::Cause cause) override;
584   void do_full_collection(bool clear_all_soft_refs) override;
585 
586   // Used for parsing heap during error printing
587   HeapWord* block_start(const void* addr) const;
588   bool block_is_obj(const HeapWord* addr) const;
589   bool print_location(outputStream* st, void* addr) const override;
590 
591   // Used for native heap walkers: heap dumpers, mostly
592   void object_iterate(ObjectClosure* cl) override;
593   // Parallel heap iteration support
594   ParallelObjectIteratorImpl* parallel_object_iterator(uint workers) override;
595 
596   // Keep alive an object that was loaded with AS_NO_KEEPALIVE.

609   void unregister_nmethod(nmethod* nm) override;
610   void verify_nmethod(nmethod* nm) override {}
611 
612 // ---------- Pinning hooks
613 //
614 public:
615   // Shenandoah supports per-object (per-region) pinning
616   void pin_object(JavaThread* thread, oop obj) override;
617   void unpin_object(JavaThread* thread, oop obj) override;
618 
619   void sync_pinned_region_status();
620   void assert_pinned_region_status() NOT_DEBUG_RETURN;
621 
622 // ---------- Concurrent Stack Processing support
623 //
624 public:
625   bool uses_stack_watermark_barrier() const override { return true; }
626 
627 // ---------- Allocation support
628 //
629 protected:
630   inline HeapWord* allocate_from_gclab(Thread* thread, size_t size);
631 
632 private:
633   HeapWord* allocate_memory_under_lock(ShenandoahAllocRequest& request, bool& in_new_region);

634   HeapWord* allocate_from_gclab_slow(Thread* thread, size_t size);
635   HeapWord* allocate_new_gclab(size_t min_size, size_t word_size, size_t* actual_size);
636 
637 public:
638   HeapWord* allocate_memory(ShenandoahAllocRequest& request);
639   HeapWord* mem_allocate(size_t size, bool* what) override;
640   MetaWord* satisfy_failed_metadata_allocation(ClassLoaderData* loader_data,
641                                                size_t size,
642                                                Metaspace::MetadataType mdtype) override;
643 
644   void notify_mutator_alloc_words(size_t words, size_t waste);
645 
646   HeapWord* allocate_new_tlab(size_t min_size, size_t requested_size, size_t* actual_size) override;
647   size_t tlab_capacity(Thread *thr) const override;
648   size_t unsafe_max_tlab_alloc(Thread *thread) const override;
649   size_t max_tlab_size() const override;
650   size_t tlab_used(Thread* ignored) const override;
651 
652   void ensure_parsability(bool retire_labs) override;
653 
654   void labs_make_parsable();
655   void tlabs_retire(bool resize);
656   void gclabs_retire(bool resize);
657 
658 // ---------- Marking support
659 //
660 private:
661   ShenandoahMarkingContext* _marking_context;
662   MemRegion  _bitmap_region;
663   MemRegion  _aux_bitmap_region;
664   MarkBitMap _verification_bit_map;
665   MarkBitMap _aux_bit_map;
666 
667   size_t _bitmap_size;
668   size_t _bitmap_regions_per_slice;
669   size_t _bitmap_bytes_per_slice;
670 
671   size_t _pretouch_heap_page_size;
672   size_t _pretouch_bitmap_page_size;
673 
674   bool _bitmap_region_special;
675   bool _aux_bitmap_region_special;
676 
677   ShenandoahLiveData** _liveness_cache;
678 
679 public:
680   inline ShenandoahMarkingContext* complete_marking_context() const;
681   inline ShenandoahMarkingContext* marking_context() const;


682 
683   template<class T>
684   inline void marked_object_iterate(ShenandoahHeapRegion* region, T* cl);
685 
686   template<class T>
687   inline void marked_object_iterate(ShenandoahHeapRegion* region, T* cl, HeapWord* limit);
688 
689   template<class T>
690   inline void marked_object_oop_iterate(ShenandoahHeapRegion* region, T* cl, HeapWord* limit);
691 


692   // SATB barriers hooks
693   inline bool requires_marking(const void* entry) const;
694 
695   // Support for bitmap uncommits
696   bool commit_bitmap_slice(ShenandoahHeapRegion *r);
697   bool uncommit_bitmap_slice(ShenandoahHeapRegion *r);
698   bool is_bitmap_slice_committed(ShenandoahHeapRegion* r, bool skip_self = false);
699 
700   // Liveness caching support
701   ShenandoahLiveData* get_liveness_cache(uint worker_id);
702   void flush_liveness_cache(uint worker_id);
703 
704   size_t pretouch_heap_page_size() { return _pretouch_heap_page_size; }
705 
706 // ---------- Evacuation support
707 //
708 private:
709   ShenandoahCollectionSet* _collection_set;
710   ShenandoahEvacOOMHandler _oom_evac_handler;
711 
712   oop try_evacuate_object(oop src, Thread* thread, ShenandoahHeapRegion* from_region, ShenandoahAffiliation target_gen);
713 public:
714 
715   static address in_cset_fast_test_addr();
716 
717   ShenandoahCollectionSet* collection_set() const { return _collection_set; }
718 
719   // Checks if object is in the collection set.
720   inline bool in_collection_set(oop obj) const;
721 
722   // Checks if location is in the collection set. Can be interior pointer, not the oop itself.
723   inline bool in_collection_set_loc(void* loc) const;
724 
725   // Evacuates or promotes object src. Returns the evacuated object, either evacuated
726   // by this thread, or by some other thread.
727   virtual oop evacuate_object(oop src, Thread* thread);
728 
729   // Call before/after evacuation.
730   inline void enter_evacuation(Thread* t);
731   inline void leave_evacuation(Thread* t);
732 
733 // ---------- Generational support
734 //
735 private:
736   RememberedScanner* _card_scan;
737 
738 public:
739   inline RememberedScanner* card_scan() { return _card_scan; }
740   void clear_cards_for(ShenandoahHeapRegion* region);
741   void mark_card_as_dirty(void* location);
742 
743 // ---------- Helper functions
744 //
745 public:
746   template <class T>
747   inline void conc_update_with_forwarded(T* p);
748 
749   template <class T>
750   inline void update_with_forwarded(T* p);
751 
752   static inline void atomic_update_oop(oop update,       oop* addr,       oop compare);
753   static inline void atomic_update_oop(oop update, narrowOop* addr,       oop compare);
754   static inline void atomic_update_oop(oop update, narrowOop* addr, narrowOop compare);
755 
756   static inline bool atomic_update_oop_check(oop update,       oop* addr,       oop compare);
757   static inline bool atomic_update_oop_check(oop update, narrowOop* addr,       oop compare);
758   static inline bool atomic_update_oop_check(oop update, narrowOop* addr, narrowOop compare);
759 
760   static inline void atomic_clear_oop(      oop* addr,       oop compare);
761   static inline void atomic_clear_oop(narrowOop* addr,       oop compare);
762   static inline void atomic_clear_oop(narrowOop* addr, narrowOop compare);
763 
764   size_t trash_humongous_region_at(ShenandoahHeapRegion *r);
765 
766   static inline void increase_object_age(oop obj, uint additional_age);
767 
768   // Return the object's age, or a sentinel value when the age can't
769   // necessarily be determined because of concurrent locking by the
770   // mutator
771   static inline uint get_object_age(oop obj);
772 
773   void log_heap_status(const char *msg) const;
774 
775 private:
776   void trash_cset_regions();
777 
778 // ---------- Testing helpers functions
779 //
780 private:
781   ShenandoahSharedFlag _inject_alloc_failure;
782 
783   void try_inject_alloc_failure();
784   bool should_inject_alloc_failure();
785 };
786 
787 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHHEAP_HPP
< prev index next >