< prev index next >

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

Print this page

  1 /*
  2  * Copyright (c) 2023, 2024, 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/heuristics/shenandoahSpaceInfo.hpp"
 33 #include "gc/shenandoah/shenandoahAsserts.hpp"
 34 #include "gc/shenandoah/shenandoahAllocRequest.hpp"


 35 #include "gc/shenandoah/shenandoahLock.hpp"
 36 #include "gc/shenandoah/shenandoahEvacOOMHandler.hpp"





 37 #include "gc/shenandoah/shenandoahPadding.hpp"
 38 #include "gc/shenandoah/shenandoahSharedVariables.hpp"
 39 #include "gc/shenandoah/shenandoahUnload.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 ShenandoahCollectorPolicy;
 48 class ShenandoahControlThread;
 49 class ShenandoahGCSession;
 50 class ShenandoahGCStateResetter;



 51 class ShenandoahHeuristics;
 52 class ShenandoahMarkingContext;
 53 class ShenandoahMode;
 54 class ShenandoahPhaseTimings;
 55 class ShenandoahHeap;
 56 class ShenandoahHeapRegion;
 57 class ShenandoahHeapRegionClosure;
 58 class ShenandoahCollectionSet;
 59 class ShenandoahFreeSet;
 60 class ShenandoahConcurrentMark;
 61 class ShenandoahFullGC;
 62 class ShenandoahMonitoringSupport;
 63 class ShenandoahPacer;
 64 class ShenandoahReferenceProcessor;
 65 class ShenandoahVerifier;
 66 class ShenandoahWorkerThreads;
 67 class VMStructs;
 68 
 69 // Used for buffering per-region liveness data.
 70 // Needed since ShenandoahHeapRegion uses atomics to update liveness.

 96 
 97   // Returns next region, or null if there are no more regions.
 98   // This is multi-thread-safe.
 99   inline ShenandoahHeapRegion* next();
100 
101   // This is *not* MT safe. However, in the absence of multithreaded access, it
102   // can be used to determine if there is more work to do.
103   bool has_next() const;
104 };
105 
106 class ShenandoahHeapRegionClosure : public StackObj {
107 public:
108   virtual void heap_region_do(ShenandoahHeapRegion* r) = 0;
109   virtual bool is_thread_safe() { return false; }
110 };
111 
112 typedef ShenandoahLock    ShenandoahHeapLock;
113 typedef ShenandoahLocker  ShenandoahHeapLocker;
114 typedef Stack<oop, mtGC>  ShenandoahScanObjectStack;
115 











116 // Shenandoah GC is low-pause concurrent GC that uses Brooks forwarding pointers
117 // to encode forwarding data. See BrooksPointer for details on forwarding data encoding.
118 // See ShenandoahControlThread for GC cycle structure.
119 //
120 class ShenandoahHeap : public CollectedHeap, public ShenandoahSpaceInfo {
121   friend class ShenandoahAsserts;
122   friend class VMStructs;
123   friend class ShenandoahGCSession;
124   friend class ShenandoahGCStateResetter;
125   friend class ShenandoahParallelObjectIterator;
126   friend class ShenandoahSafepoint;
127 
128   // Supported GC
129   friend class ShenandoahConcurrentGC;

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

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











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

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


187 public:
188   void increase_used(size_t bytes);
189   void decrease_used(size_t bytes);
190   void set_used(size_t bytes);

191 
192   void increase_committed(size_t bytes);
193   void decrease_committed(size_t bytes);
194   void increase_allocated(size_t bytes);
195 
196   size_t bytes_allocated_since_gc_start() const override;
197   void reset_bytes_allocated_since_gc_start();
198 
199   size_t min_capacity()      const;
200   size_t max_capacity()      const override;
201   size_t soft_max_capacity() const override;
202   size_t initial_capacity()  const;
203   size_t capacity()          const override;
204   size_t used()              const override;
205   size_t committed()         const;
206   size_t available()         const override;
207 
208   void set_soft_max_capacity(size_t v);
209 
210 // ---------- Periodic Tasks
211 //
212 private:
213   void notify_heap_changed();
214 
215 public:
216   void set_forced_counters_update(bool value);
217   void handle_force_counters_update();
218 
219 // ---------- Workers handling
220 //
221 private:
222   uint _max_workers;
223   ShenandoahWorkerThreads* _workers;
224   ShenandoahWorkerThreads* _safepoint_workers;
225 


226 public:
227   uint max_workers();
228   void assert_gc_workers(uint nworker) NOT_DEBUG_RETURN;
229 
230   WorkerThreads* workers() const;
231   WorkerThreads* safepoint_workers() override;
232 
233   void gc_threads_do(ThreadClosure* tcl) const override;
234 
235 // ---------- Heap regions handling machinery
236 //
237 private:
238   MemRegion _heap_region;
239   bool      _heap_region_special;
240   size_t    _num_regions;
241   ShenandoahHeapRegion** _regions;
242   ShenandoahRegionIterator _update_refs_iterator;
243 
244 public:
245 
246   inline HeapWord* base() const { return _heap_region.start(); }
247 
248   inline size_t num_regions() const { return _num_regions; }
249   inline bool is_heap_region_special() { return _heap_region_special; }
250 
251   inline ShenandoahHeapRegion* heap_region_containing(const void* addr) const;
252   inline size_t heap_region_index_containing(const void* addr) const;
253 
254   inline ShenandoahHeapRegion* get_region(size_t region_idx) const;
255 
256   void heap_region_iterate(ShenandoahHeapRegionClosure* blk) const;
257   void parallel_heap_region_iterate(ShenandoahHeapRegionClosure* blk) const;
258 


259 // ---------- GC state machinery
260 //
261 // GC state describes the important parts of collector state, that may be
262 // used to make barrier selection decisions in the native and generated code.
263 // Multiple bits can be set at once.
264 //
265 // Important invariant: when GC state is zero, the heap is stable, and no barriers
266 // are required.
267 //
268 public:
269   enum GCStateBitPos {
270     // Heap has forwarded objects: needs LRB barriers.
271     HAS_FORWARDED_BITPOS   = 0,
272 
273     // Heap is under marking: needs SATB barriers.

274     MARKING_BITPOS    = 1,
275 
276     // Heap is under evacuation: needs LRB barriers. (Set together with HAS_FORWARDED)
277     EVACUATION_BITPOS = 2,
278 
279     // Heap is under updating: needs no additional barriers.
280     UPDATEREFS_BITPOS = 3,
281 
282     // Heap is under weak-reference/roots processing: needs weak-LRB barriers.
283     WEAK_ROOTS_BITPOS  = 4,






284   };
285 
286   enum GCState {
287     STABLE        = 0,
288     HAS_FORWARDED = 1 << HAS_FORWARDED_BITPOS,
289     MARKING       = 1 << MARKING_BITPOS,
290     EVACUATION    = 1 << EVACUATION_BITPOS,
291     UPDATEREFS    = 1 << UPDATEREFS_BITPOS,
292     WEAK_ROOTS    = 1 << WEAK_ROOTS_BITPOS,


293   };
294 
295 private:
296   bool _gc_state_changed;
297   ShenandoahSharedBitmap _gc_state;
298 
299   // tracks if new regions have been allocated or retired since last check
300   ShenandoahSharedFlag   _heap_changed;
301   ShenandoahSharedFlag   _degenerated_gc_in_progress;
302   ShenandoahSharedFlag   _full_gc_in_progress;
303   ShenandoahSharedFlag   _full_gc_move_in_progress;
304   ShenandoahSharedFlag   _concurrent_strong_root_in_progress;
305 
306   size_t _gc_no_progress_count;
307 
308   // This updates the singlular, global gc state. This must happen on a safepoint.
309   void set_gc_state(uint mask, bool value);
310 
311 public:
312   char gc_state() const;
313 
314   // This copies the global gc state into a thread local variable for java threads.
315   // It is primarily intended to support quick access at barriers.
316   void propagate_gc_state_to_java_threads();
317 
318   // This is public to support assertions that the state hasn't been changed off of
319   // a safepoint and that any changes were propagated to java threads after the safepoint.
320   bool has_gc_state_changed() const { return _gc_state_changed; }
321 
322   // Returns true if allocations have occurred in new regions or if regions have been
323   // uncommitted since the previous calls. This call will reset the flag to false.
324   bool has_changed() {
325     return _heap_changed.try_unset();
326   }
327 
328   void set_concurrent_mark_in_progress(bool in_progress);

329   void set_evacuation_in_progress(bool in_progress);
330   void set_update_refs_in_progress(bool in_progress);
331   void set_degenerated_gc_in_progress(bool in_progress);
332   void set_full_gc_in_progress(bool in_progress);
333   void set_full_gc_move_in_progress(bool in_progress);
334   void set_has_forwarded_objects(bool cond);
335   void set_concurrent_strong_root_in_progress(bool cond);
336   void set_concurrent_weak_root_in_progress(bool cond);
337 
338   inline bool is_stable() const;
339   inline bool is_idle() const;

340   inline bool is_concurrent_mark_in_progress() const;


341   inline bool is_update_refs_in_progress() const;
342   inline bool is_evacuation_in_progress() const;
343   inline bool is_degenerated_gc_in_progress() const;
344   inline bool is_full_gc_in_progress() const;
345   inline bool is_full_gc_move_in_progress() const;
346   inline bool has_forwarded_objects() const;
347 
348   inline bool is_stw_gc_in_progress() const;
349   inline bool is_concurrent_strong_root_in_progress() const;
350   inline bool is_concurrent_weak_root_in_progress() const;

351 
352 private:


353   enum CancelState {
354     // Normal state. GC has not been cancelled and is open for cancellation.
355     // Worker threads can suspend for safepoint.
356     CANCELLABLE,
357 
358     // GC has been cancelled. Worker threads can not suspend for
359     // safepoint but must finish their work as soon as possible.
360     CANCELLED
361   };
362 

363   ShenandoahSharedEnumFlag<CancelState> _cancelled_gc;





364   bool try_cancel_gc();
365 
366 public:
367 
368   inline bool cancelled_gc() const;
369   inline bool check_cancelled_gc_and_yield(bool sts_active = true);
370 
371   inline void clear_cancelled_gc();
372 

373   void cancel_gc(GCCause::Cause cause);
374 
375 public:
376   // These will uncommit empty regions if heap::committed > shrink_until
377   // and there exists at least one region which was made empty before shrink_before.
378   void maybe_uncommit(double shrink_before, size_t shrink_until);
379   void op_uncommit(double shrink_before, size_t shrink_until);
380 
381   // Returns true if the soft maximum heap has been changed using management APIs.
382   bool check_soft_max_changed();
383 






384 private:
385   // GC support
386   // Reset bitmap, prepare regions for new GC cycle
387   void prepare_gc();
388   void prepare_regions_and_collection_set(bool concurrent);
389   // Evacuation
390   void evacuate_collection_set(bool concurrent);
391   // Concurrent root processing
392   void prepare_concurrent_roots();
393   void finish_concurrent_roots();
394   // Concurrent class unloading support
395   void do_class_unloading();
396   // Reference updating
397   void prepare_update_heap_references(bool concurrent);
398   void update_heap_references(bool concurrent);
399   // Final update region states
400   void update_heap_region_states(bool concurrent);
401   void rebuild_free_set(bool concurrent);
402 
403   void rendezvous_threads();
404   void recycle_trash();
405 public:

406   void notify_gc_progress();
407   void notify_gc_no_progress();
408   size_t get_gc_no_progress_count() const;
409 
410 //
411 // Mark support
412 private:
413   ShenandoahControlThread*   _control_thread;








414   ShenandoahCollectorPolicy* _shenandoah_policy;
415   ShenandoahMode*            _gc_mode;
416   ShenandoahHeuristics*      _heuristics;
417   ShenandoahFreeSet*         _free_set;
418   ShenandoahPacer*           _pacer;
419   ShenandoahVerifier*        _verifier;
420 
421   ShenandoahPhaseTimings*    _phase_timings;
422 
423   ShenandoahControlThread*   control_thread()          { return _control_thread;    }
424 
425 public:















426   ShenandoahCollectorPolicy* shenandoah_policy() const { return _shenandoah_policy; }
427   ShenandoahMode*            mode()              const { return _gc_mode;           }
428   ShenandoahHeuristics*      heuristics()        const { return _heuristics;        }
429   ShenandoahFreeSet*         free_set()          const { return _free_set;          }
430   ShenandoahPacer*           pacer()             const { return _pacer;             }
431 
432   ShenandoahPhaseTimings*    phase_timings()     const { return _phase_timings;     }






433 
434   ShenandoahVerifier*        verifier();
435 
436 // ---------- VM subsystem bindings
437 //
438 private:
439   ShenandoahMonitoringSupport* _monitoring_support;
440   MemoryPool*                  _memory_pool;
441   GCMemoryManager              _stw_memory_manager;
442   GCMemoryManager              _cycle_memory_manager;
443   ConcurrentGCTimer*           _gc_timer;
444   // For exporting to SA
445   int                          _log_min_obj_alignment_in_bytes;
446 public:
447   ShenandoahMonitoringSupport* monitoring_support()          { return _monitoring_support;    }
448   GCMemoryManager* cycle_memory_manager()                    { return &_cycle_memory_manager; }
449   GCMemoryManager* stw_memory_manager()                      { return &_stw_memory_manager;   }
450 
451   GrowableArray<GCMemoryManager*> memory_managers() override;
452   GrowableArray<MemoryPool*> memory_pools() override;
453   MemoryUsage memory_usage() override;
454   GCTracer* tracer();
455   ConcurrentGCTimer* gc_timer() const;
456 
457 // ---------- Reference processing
458 //
459 private:
460   ShenandoahReferenceProcessor* const _ref_processor;
461 
462 public:
463   ShenandoahReferenceProcessor* ref_processor() { return _ref_processor; }
464 
465 // ---------- Class Unloading
466 //
467 private:
468   ShenandoahSharedFlag _unload_classes;
469   ShenandoahUnload     _unloader;
470 
471 public:
472   void set_unload_classes(bool uc);
473   bool unload_classes() const;
474 
475   // Perform STW class unloading and weak root cleaning
476   void parallel_cleaning(bool full_gc);
477 
478 private:
479   void stw_unload_classes(bool full_gc);
480   void stw_process_weak_roots(bool full_gc);
481   void stw_weak_refs(bool full_gc);
482 



483   // Heap iteration support
484   void scan_roots_for_iteration(ShenandoahScanObjectStack* oop_stack, ObjectIterateScanRootClosure* oops);
485   bool prepare_aux_bitmap_for_iteration();
486   void reclaim_aux_bitmap_for_iteration();
487 
488 // ---------- Generic interface hooks
489 // Minor things that super-interface expects us to implement to play nice with
490 // the rest of runtime. Some of the things here are not required to be implemented,
491 // and can be stubbed out.
492 //
493 public:
494   bool is_maximal_no_gc() const override shenandoah_not_implemented_return(false);
495 
496   bool is_in(const void* p) const override;










497 
498   bool requires_barriers(stackChunkOop obj) const override;
499 
500   MemRegion reserved_region() const { return _reserved; }
501   bool is_in_reserved(const void* addr) const { return _reserved.contains(addr); }
502 
503   void collect(GCCause::Cause cause) override;
504   void do_full_collection(bool clear_all_soft_refs) override;
505 
506   // Used for parsing heap during error printing
507   HeapWord* block_start(const void* addr) const;
508   bool block_is_obj(const HeapWord* addr) const;
509   bool print_location(outputStream* st, void* addr) const override;
510 
511   // Used for native heap walkers: heap dumpers, mostly
512   void object_iterate(ObjectClosure* cl) override;
513   // Parallel heap iteration support
514   ParallelObjectIteratorImpl* parallel_object_iterator(uint workers) override;
515 
516   // Keep alive an object that was loaded with AS_NO_KEEPALIVE.

524 
525 // ---------- Code roots handling hooks
526 //
527 public:
528   void register_nmethod(nmethod* nm) override;
529   void unregister_nmethod(nmethod* nm) override;
530   void verify_nmethod(nmethod* nm) override {}
531 
532 // ---------- Pinning hooks
533 //
534 public:
535   // Shenandoah supports per-object (per-region) pinning
536   void pin_object(JavaThread* thread, oop obj) override;
537   void unpin_object(JavaThread* thread, oop obj) override;
538 
539   void sync_pinned_region_status();
540   void assert_pinned_region_status() NOT_DEBUG_RETURN;
541 
542 // ---------- Allocation support
543 //



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

629 public:

630   static address in_cset_fast_test_addr();
631 
632   ShenandoahCollectionSet* collection_set() const { return _collection_set; }
633 
634   // Checks if object is in the collection set.
635   inline bool in_collection_set(oop obj) const;
636 
637   // Checks if location is in the collection set. Can be interior pointer, not the oop itself.
638   inline bool in_collection_set_loc(void* loc) const;
639 
640   // Evacuates object src. Returns the evacuated object, either evacuated
641   // by this thread, or by some other thread.
642   oop evacuate_object(oop src, Thread* thread);
643 
644   // Call before/after evacuation.
645   inline void enter_evacuation(Thread* t);
646   inline void leave_evacuation(Thread* t);
647 
648 // ---------- Helper functions
649 //
650 public:
651   template <class T>
652   inline void conc_update_with_forwarded(T* p);
653 
654   template <class T>
655   inline void update_with_forwarded(T* p);
656 
657   static inline void atomic_update_oop(oop update,       oop* addr,       oop compare);
658   static inline void atomic_update_oop(oop update, narrowOop* addr,       oop compare);
659   static inline void atomic_update_oop(oop update, narrowOop* addr, narrowOop compare);
660 
661   static inline bool atomic_update_oop_check(oop update,       oop* addr,       oop compare);
662   static inline bool atomic_update_oop_check(oop update, narrowOop* addr,       oop compare);
663   static inline bool atomic_update_oop_check(oop update, narrowOop* addr, narrowOop compare);
664 
665   static inline void atomic_clear_oop(      oop* addr,       oop compare);
666   static inline void atomic_clear_oop(narrowOop* addr,       oop compare);
667   static inline void atomic_clear_oop(narrowOop* addr, narrowOop compare);
668 
669   void trash_humongous_region_at(ShenandoahHeapRegion *r);









670 
671 private:
672   void trash_cset_regions();
673 
674 // ---------- Testing helpers functions
675 //
676 private:
677   ShenandoahSharedFlag _inject_alloc_failure;
678 
679   void try_inject_alloc_failure();
680   bool should_inject_alloc_failure();
681 };
682 
683 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHHEAP_HPP

  1 /*
  2  * Copyright (c) 2023, 2024, 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/markBitMap.hpp"
 31 #include "gc/shared/softRefPolicy.hpp"
 32 #include "gc/shared/collectedHeap.hpp"
 33 #include "gc/shenandoah/heuristics/shenandoahSpaceInfo.hpp"

 34 #include "gc/shenandoah/shenandoahAllocRequest.hpp"
 35 #include "gc/shenandoah/shenandoahAsserts.hpp"
 36 #include "gc/shenandoah/shenandoahController.hpp"
 37 #include "gc/shenandoah/shenandoahLock.hpp"
 38 #include "gc/shenandoah/shenandoahEvacOOMHandler.hpp"
 39 #include "gc/shenandoah/shenandoahEvacTracker.hpp"
 40 #include "gc/shenandoah/shenandoahGenerationType.hpp"
 41 #include "gc/shenandoah/shenandoahGenerationSizer.hpp"
 42 #include "gc/shenandoah/shenandoahMmuTracker.hpp"
 43 #include "gc/shenandoah/mode/shenandoahMode.hpp"
 44 #include "gc/shenandoah/shenandoahPadding.hpp"
 45 #include "gc/shenandoah/shenandoahSharedVariables.hpp"
 46 #include "gc/shenandoah/shenandoahUnload.hpp"
 47 #include "memory/metaspace.hpp"
 48 #include "services/memoryManager.hpp"
 49 #include "utilities/globalDefinitions.hpp"
 50 #include "utilities/stack.hpp"
 51 
 52 class ConcurrentGCTimer;
 53 class ObjectIterateScanRootClosure;
 54 class ShenandoahCollectorPolicy;

 55 class ShenandoahGCSession;
 56 class ShenandoahGCStateResetter;
 57 class ShenandoahGeneration;
 58 class ShenandoahYoungGeneration;
 59 class ShenandoahOldGeneration;
 60 class ShenandoahHeuristics;
 61 class ShenandoahMarkingContext;
 62 class ShenandoahMode;
 63 class ShenandoahPhaseTimings;
 64 class ShenandoahHeap;
 65 class ShenandoahHeapRegion;
 66 class ShenandoahHeapRegionClosure;
 67 class ShenandoahCollectionSet;
 68 class ShenandoahFreeSet;
 69 class ShenandoahConcurrentMark;
 70 class ShenandoahFullGC;
 71 class ShenandoahMonitoringSupport;
 72 class ShenandoahPacer;
 73 class ShenandoahReferenceProcessor;
 74 class ShenandoahVerifier;
 75 class ShenandoahWorkerThreads;
 76 class VMStructs;
 77 
 78 // Used for buffering per-region liveness data.
 79 // Needed since ShenandoahHeapRegion uses atomics to update liveness.

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

216   volatile size_t _committed;

217   shenandoah_padding(1);
218 
219   void increase_used(const ShenandoahAllocRequest& req);
220 
221 public:
222   void increase_used(ShenandoahGeneration* generation, size_t bytes);
223   void decrease_used(ShenandoahGeneration* generation, size_t bytes);
224   void increase_humongous_waste(ShenandoahGeneration* generation, size_t bytes);
225   void decrease_humongous_waste(ShenandoahGeneration* generation, size_t bytes);
226 
227   void increase_committed(size_t bytes);
228   void decrease_committed(size_t bytes);

229 

230   void reset_bytes_allocated_since_gc_start();
231 
232   size_t min_capacity()      const;
233   size_t max_capacity()      const override;
234   size_t soft_max_capacity() const;
235   size_t initial_capacity()  const;
236   size_t capacity()          const override;
237   size_t used()              const override;
238   size_t committed()         const;

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


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

423   inline bool cancelled_gc() const;
424   inline bool check_cancelled_gc_and_yield(bool sts_active = true);
425 
426   inline void clear_cancelled_gc(bool clear_oom_handler = true);
427 
428   void cancel_concurrent_mark();
429   void cancel_gc(GCCause::Cause cause);
430 
431 public:
432   // These will uncommit empty regions if heap::committed > shrink_until
433   // and there exists at least one region which was made empty before shrink_before.
434   void maybe_uncommit(double shrink_before, size_t shrink_until);
435   void op_uncommit(double shrink_before, size_t shrink_until);
436 
437   // Returns true if the soft maximum heap has been changed using management APIs.
438   bool check_soft_max_changed();
439 
440 protected:
441   // This is shared between shConcurrentGC and shDegenerateGC so that degenerated
442   // GC can resume update refs from where the concurrent GC was cancelled. It is
443   // also used in shGenerationalHeap, which uses a different closure for update refs.
444   ShenandoahRegionIterator _update_refs_iterator;
445 
446 private:
447   // GC support



448   // Evacuation
449   void evacuate_collection_set(bool concurrent);
450   // Concurrent root processing
451   void prepare_concurrent_roots();
452   void finish_concurrent_roots();
453   // Concurrent class unloading support
454   void do_class_unloading();
455   // Reference updating
456   void prepare_update_heap_references(bool concurrent);
457   virtual void update_heap_references(bool concurrent);
458   // Final update region states
459   void update_heap_region_states(bool concurrent);
460   virtual void final_update_refs_update_region_states();
461 
462   void rendezvous_threads();
463   void recycle_trash();
464 public:
465   void rebuild_free_set(bool concurrent);
466   void notify_gc_progress();
467   void notify_gc_no_progress();
468   size_t get_gc_no_progress_count() const;
469 
470 //
471 // Mark support
472 private:
473   ShenandoahGeneration*  _global_generation;
474 
475 protected:
476   ShenandoahController*  _control_thread;
477 
478   ShenandoahYoungGeneration* _young_generation;
479   ShenandoahOldGeneration*   _old_generation;
480 
481 private:
482   ShenandoahCollectorPolicy* _shenandoah_policy;
483   ShenandoahMode*            _gc_mode;

484   ShenandoahFreeSet*         _free_set;
485   ShenandoahPacer*           _pacer;
486   ShenandoahVerifier*        _verifier;
487 
488   ShenandoahPhaseTimings*       _phase_timings;
489   ShenandoahEvacuationTracker*  _evac_tracker;
490   ShenandoahMmuTracker          _mmu_tracker;
491 
492 public:
493   ShenandoahController*   control_thread() { return _control_thread; }
494 
495   ShenandoahGeneration*      global_generation() const { return _global_generation; }
496   ShenandoahYoungGeneration* young_generation()  const {
497     assert(mode()->is_generational(), "Young generation requires generational mode");
498     return _young_generation;
499   }
500 
501   ShenandoahOldGeneration*   old_generation()    const {
502     assert(mode()->is_generational(), "Old generation requires generational mode");
503     return _old_generation;
504   }
505 
506   ShenandoahGeneration*      generation_for(ShenandoahAffiliation affiliation) const;
507 
508   ShenandoahCollectorPolicy* shenandoah_policy() const { return _shenandoah_policy; }
509   ShenandoahMode*            mode()              const { return _gc_mode;           }

510   ShenandoahFreeSet*         free_set()          const { return _free_set;          }
511   ShenandoahPacer*           pacer()             const { return _pacer;             }
512 
513   ShenandoahPhaseTimings*      phase_timings()   const { return _phase_timings;     }
514   ShenandoahEvacuationTracker* evac_tracker()    const { return _evac_tracker;      }
515 
516   ShenandoahEvacOOMHandler* oom_evac_handler() { return &_oom_evac_handler; }
517 
518   void on_cycle_start(GCCause::Cause cause, ShenandoahGeneration* generation);
519   void on_cycle_end(ShenandoahGeneration* generation);
520 
521   ShenandoahVerifier*        verifier();
522 
523 // ---------- VM subsystem bindings
524 //
525 private:
526   ShenandoahMonitoringSupport* _monitoring_support;
527   MemoryPool*                  _memory_pool;
528   GCMemoryManager              _stw_memory_manager;
529   GCMemoryManager              _cycle_memory_manager;
530   ConcurrentGCTimer*           _gc_timer;
531   // For exporting to SA
532   int                          _log_min_obj_alignment_in_bytes;
533 public:
534   ShenandoahMonitoringSupport* monitoring_support() const    { return _monitoring_support;    }
535   GCMemoryManager* cycle_memory_manager()                    { return &_cycle_memory_manager; }
536   GCMemoryManager* stw_memory_manager()                      { return &_stw_memory_manager;   }
537 
538   GrowableArray<GCMemoryManager*> memory_managers() override;
539   GrowableArray<MemoryPool*> memory_pools() override;
540   MemoryUsage memory_usage() override;
541   GCTracer* tracer();
542   ConcurrentGCTimer* gc_timer() const;
543 








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

616 
617 // ---------- Code roots handling hooks
618 //
619 public:
620   void register_nmethod(nmethod* nm) override;
621   void unregister_nmethod(nmethod* nm) override;
622   void verify_nmethod(nmethod* nm) override {}
623 
624 // ---------- Pinning hooks
625 //
626 public:
627   // Shenandoah supports per-object (per-region) pinning
628   void pin_object(JavaThread* thread, oop obj) override;
629   void unpin_object(JavaThread* thread, oop obj) override;
630 
631   void sync_pinned_region_status();
632   void assert_pinned_region_status() NOT_DEBUG_RETURN;
633 
634 // ---------- Allocation support
635 //
636 protected:
637   inline HeapWord* allocate_from_gclab(Thread* thread, size_t size);
638 
639 private:
640   HeapWord* allocate_memory_under_lock(ShenandoahAllocRequest& request, bool& in_new_region);

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


689 
690   template<class T>
691   inline void marked_object_iterate(ShenandoahHeapRegion* region, T* cl);
692 
693   template<class T>
694   inline void marked_object_iterate(ShenandoahHeapRegion* region, T* cl, HeapWord* limit);
695 
696   template<class T>
697   inline void marked_object_oop_iterate(ShenandoahHeapRegion* region, T* cl, HeapWord* limit);
698 


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