1 /* 2 * Copyright (c) 2013, 2020, Red Hat, Inc. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHHEAP_HPP 26 #define SHARE_GC_SHENANDOAH_SHENANDOAHHEAP_HPP 27 28 #include "gc/shared/markBitMap.hpp" 29 #include "gc/shared/softRefPolicy.hpp" 30 #include "gc/shared/collectedHeap.hpp" 31 #include "gc/shenandoah/shenandoahAsserts.hpp" 32 #include "gc/shenandoah/shenandoahAllocRequest.hpp" 33 #include "gc/shenandoah/shenandoahLock.hpp" 34 #include "gc/shenandoah/shenandoahEvacOOMHandler.hpp" 35 #include "gc/shenandoah/shenandoahPadding.hpp" 36 #include "gc/shenandoah/shenandoahSharedVariables.hpp" 37 #include "gc/shenandoah/shenandoahUnload.hpp" 38 #include "services/memoryManager.hpp" 39 #include "utilities/globalDefinitions.hpp" 40 41 class ConcurrentGCTimer; 42 class ReferenceProcessor; 43 class ShenandoahCollectorPolicy; 44 class ShenandoahControlThread; 45 class ShenandoahGCSession; 46 class ShenandoahGCStateResetter; 47 class ShenandoahHeuristics; 48 class ShenandoahMarkingContext; 49 class ShenandoahMarkCompact; 50 class ShenandoahMode; 51 class ShenandoahPhaseTimings; 52 class ShenandoahHeap; 53 class ShenandoahHeapRegion; 54 class ShenandoahHeapRegionClosure; 55 class ShenandoahCollectionSet; 56 class ShenandoahFreeSet; 57 class ShenandoahConcurrentMark; 58 class ShenandoahMarkCompact; 59 class ShenandoahMonitoringSupport; 60 class ShenandoahPacer; 61 class ShenandoahVerifier; 62 class ShenandoahWorkGang; 63 class VMStructs; 64 65 // Used for buffering per-region liveness data. 66 // Needed since ShenandoahHeapRegion uses atomics to update liveness. 67 // The ShenandoahHeap array has max-workers elements, each of which is an array of 68 // uint16_t * max_regions. The choice of uint16_t is not accidental: 69 // there is a tradeoff between static/dynamic footprint that translates 70 // into cache pressure (which is already high during marking), and 71 // too many atomic updates. uint32_t is too large, uint8_t is too small. 72 typedef uint16_t ShenandoahLiveData; 73 #define SHENANDOAH_LIVEDATA_MAX ((ShenandoahLiveData)-1) 74 75 class ShenandoahRegionIterator : public StackObj { 76 private: 77 ShenandoahHeap* _heap; 78 79 shenandoah_padding(0); 80 volatile size_t _index; 81 shenandoah_padding(1); 82 83 // No implicit copying: iterators should be passed by reference to capture the state 84 NONCOPYABLE(ShenandoahRegionIterator); 85 86 public: 87 ShenandoahRegionIterator(); 88 ShenandoahRegionIterator(ShenandoahHeap* heap); 89 90 // Reset iterator to default state 91 void reset(); 92 93 // Returns next region, or NULL if there are no more regions. 94 // This is multi-thread-safe. 95 inline ShenandoahHeapRegion* next(); 96 97 // This is *not* MT safe. However, in the absence of multithreaded access, it 98 // can be used to determine if there is more work to do. 99 bool has_next() const; 100 }; 101 102 class ShenandoahHeapRegionClosure : public StackObj { 103 public: 104 virtual void heap_region_do(ShenandoahHeapRegion* r) = 0; 105 virtual bool is_thread_safe() { return false; } 106 }; 107 108 #ifdef ASSERT 109 class ShenandoahAssertToSpaceClosure : public OopClosure { 110 private: 111 template <class T> 112 void do_oop_work(T* p); 113 public: 114 void do_oop(narrowOop* p); 115 void do_oop(oop* p); 116 }; 117 #endif 118 119 typedef ShenandoahLock ShenandoahHeapLock; 120 typedef ShenandoahLocker ShenandoahHeapLocker; 121 122 // Shenandoah GC is low-pause concurrent GC that uses Brooks forwarding pointers 123 // to encode forwarding data. See BrooksPointer for details on forwarding data encoding. 124 // See ShenandoahControlThread for GC cycle structure. 125 // 126 class ShenandoahHeap : public CollectedHeap { 127 friend class ShenandoahAsserts; 128 friend class VMStructs; 129 friend class ShenandoahGCSession; 130 friend class ShenandoahGCStateResetter; 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 private: 145 static ShenandoahHeap* _heap; 146 147 public: 148 static ShenandoahHeap* heap(); 149 150 const char* name() const { return "Shenandoah"; } 151 ShenandoahHeap::Name kind() const { return CollectedHeap::Shenandoah; } 152 153 ShenandoahHeap(ShenandoahCollectorPolicy* policy); 154 jint initialize(); 155 void post_initialize(); 156 void initialize_heuristics(); 157 158 void initialize_serviceability(); 159 160 void print_on(outputStream* st) const; 161 void print_extended_on(outputStream *st) const; 162 void print_tracing_info() const; 163 void print_gc_threads_on(outputStream* st) const; 164 void print_heap_regions_on(outputStream* st) const; 165 166 void stop(); 167 168 void prepare_for_verify(); 169 void verify(VerifyOption vo); 170 171 // ---------- Heap counters and metrics 172 // 173 private: 174 size_t _initial_size; 175 size_t _minimum_size; 176 shenandoah_padding(0); 177 volatile size_t _used; 178 volatile size_t _committed; 179 volatile size_t _bytes_allocated_since_gc_start; 180 shenandoah_padding(1); 181 182 public: 183 void increase_used(size_t bytes); 184 void decrease_used(size_t bytes); 185 void set_used(size_t bytes); 186 187 void increase_committed(size_t bytes); 188 void decrease_committed(size_t bytes); 189 void increase_allocated(size_t bytes); 190 191 size_t bytes_allocated_since_gc_start(); 192 void reset_bytes_allocated_since_gc_start(); 193 194 size_t min_capacity() const; 195 size_t max_capacity() const; 196 size_t initial_capacity() const; 197 size_t capacity() const; 198 size_t used() const; 199 size_t committed() const; 200 201 // ---------- Workers handling 202 // 203 private: 204 uint _max_workers; 205 ShenandoahWorkGang* _workers; 206 ShenandoahWorkGang* _safepoint_workers; 207 208 public: 209 uint max_workers(); 210 void assert_gc_workers(uint nworker) NOT_DEBUG_RETURN; 211 212 WorkGang* workers() const; 213 WorkGang* get_safepoint_workers(); 214 215 void gc_threads_do(ThreadClosure* tcl) const; 216 217 // ---------- Heap regions handling machinery 218 // 219 private: 220 MemRegion _heap_region; 221 bool _heap_region_special; 222 size_t _num_regions; 223 ShenandoahHeapRegion** _regions; 224 ShenandoahRegionIterator _update_refs_iterator; 225 226 public: 227 228 inline HeapWord* base() const { return _heap_region.start(); } 229 230 inline size_t num_regions() const { return _num_regions; } 231 inline bool is_heap_region_special() { return _heap_region_special; } 232 233 inline ShenandoahHeapRegion* const heap_region_containing(const void* addr) const; 234 inline size_t heap_region_index_containing(const void* addr) const; 235 236 inline ShenandoahHeapRegion* const get_region(size_t region_idx) const; 237 238 void heap_region_iterate(ShenandoahHeapRegionClosure* blk) const; 239 void parallel_heap_region_iterate(ShenandoahHeapRegionClosure* blk) const; 240 241 // ---------- GC state machinery 242 // 243 // GC state describes the important parts of collector state, that may be 244 // used to make barrier selection decisions in the native and generated code. 245 // Multiple bits can be set at once. 246 // 247 // Important invariant: when GC state is zero, the heap is stable, and no barriers 248 // are required. 249 // 250 public: 251 enum GCStateBitPos { 252 // Heap has forwarded objects: needs LRB barriers. 253 HAS_FORWARDED_BITPOS = 0, 254 255 // Heap is under marking: needs SATB barriers. 256 MARKING_BITPOS = 1, 257 258 // Heap is under evacuation: needs LRB barriers. (Set together with HAS_FORWARDED) 259 EVACUATION_BITPOS = 2, 260 261 // Heap is under updating: needs no additional barriers. 262 UPDATEREFS_BITPOS = 3, 263 }; 264 265 enum GCState { 266 STABLE = 0, 267 HAS_FORWARDED = 1 << HAS_FORWARDED_BITPOS, 268 MARKING = 1 << MARKING_BITPOS, 269 EVACUATION = 1 << EVACUATION_BITPOS, 270 UPDATEREFS = 1 << UPDATEREFS_BITPOS, 271 }; 272 273 private: 274 ShenandoahSharedBitmap _gc_state; 275 ShenandoahSharedFlag _degenerated_gc_in_progress; 276 ShenandoahSharedFlag _full_gc_in_progress; 277 ShenandoahSharedFlag _full_gc_move_in_progress; 278 ShenandoahSharedFlag _progress_last_gc; 279 ShenandoahSharedFlag _concurrent_strong_root_in_progress; 280 ShenandoahSharedFlag _concurrent_weak_root_in_progress; 281 282 void set_gc_state_all_threads(char state); 283 void set_gc_state_mask(uint mask, bool value); 284 285 public: 286 char gc_state() const; 287 static address gc_state_addr(); 288 289 void set_concurrent_mark_in_progress(bool in_progress); 290 void set_evacuation_in_progress(bool in_progress); 291 void set_update_refs_in_progress(bool in_progress); 292 void set_degenerated_gc_in_progress(bool in_progress); 293 void set_full_gc_in_progress(bool in_progress); 294 void set_full_gc_move_in_progress(bool in_progress); 295 void set_has_forwarded_objects(bool cond); 296 void set_concurrent_strong_root_in_progress(bool cond); 297 void set_concurrent_weak_root_in_progress(bool cond); 298 299 inline bool is_stable() const; 300 inline bool is_idle() const; 301 inline bool is_concurrent_mark_in_progress() const; 302 inline bool is_update_refs_in_progress() const; 303 inline bool is_evacuation_in_progress() const; 304 inline bool is_degenerated_gc_in_progress() const; 305 inline bool is_full_gc_in_progress() const; 306 inline bool is_full_gc_move_in_progress() const; 307 inline bool has_forwarded_objects() const; 308 inline bool is_gc_in_progress_mask(uint mask) const; 309 inline bool is_stw_gc_in_progress() const; 310 inline bool is_concurrent_strong_root_in_progress() const; 311 inline bool is_concurrent_weak_root_in_progress() const; 312 313 // ---------- GC cancellation and degeneration machinery 314 // 315 // Cancelled GC flag is used to notify concurrent phases that they should terminate. 316 // 317 public: 318 enum ShenandoahDegenPoint { 319 _degenerated_unset, 320 _degenerated_outside_cycle, 321 _degenerated_mark, 322 _degenerated_evac, 323 _degenerated_updaterefs, 324 _DEGENERATED_LIMIT 325 }; 326 327 static const char* degen_point_to_string(ShenandoahDegenPoint point) { 328 switch (point) { 329 case _degenerated_unset: 330 return "<UNSET>"; 331 case _degenerated_outside_cycle: 332 return "Outside of Cycle"; 333 case _degenerated_mark: 334 return "Mark"; 335 case _degenerated_evac: 336 return "Evacuation"; 337 case _degenerated_updaterefs: 338 return "Update Refs"; 339 default: 340 ShouldNotReachHere(); 341 return "ERROR"; 342 } 343 }; 344 345 private: 346 enum CancelState { 347 // Normal state. GC has not been cancelled and is open for cancellation. 348 // Worker threads can suspend for safepoint. 349 CANCELLABLE, 350 351 // GC has been cancelled. Worker threads can not suspend for 352 // safepoint but must finish their work as soon as possible. 353 CANCELLED, 354 355 // GC has not been cancelled and must not be cancelled. At least 356 // one worker thread checks for pending safepoint and may suspend 357 // if a safepoint is pending. 358 NOT_CANCELLED 359 }; 360 361 ShenandoahSharedEnumFlag<CancelState> _cancelled_gc; 362 bool try_cancel_gc(); 363 364 public: 365 static address cancelled_gc_addr(); 366 367 inline bool cancelled_gc() const; 368 inline bool check_cancelled_gc_and_yield(bool sts_active = true); 369 370 inline void clear_cancelled_gc(); 371 372 void cancel_gc(GCCause::Cause cause); 373 374 // ---------- GC operations entry points 375 // 376 public: 377 // Entry points to STW GC operations, these cause a related safepoint, that then 378 // call the entry method below 379 void vmop_entry_init_mark(); 380 void vmop_entry_final_mark(); 381 void vmop_entry_init_updaterefs(); 382 void vmop_entry_final_updaterefs(); 383 void vmop_entry_full(GCCause::Cause cause); 384 void vmop_degenerated(ShenandoahDegenPoint point); 385 386 // Entry methods to normally STW GC operations. These set up logging, monitoring 387 // and workers for net VM operation 388 void entry_init_mark(); 389 void entry_final_mark(); 390 void entry_init_updaterefs(); 391 void entry_final_updaterefs(); 392 void entry_full(GCCause::Cause cause); 393 void entry_degenerated(int point); 394 395 // Entry methods to normally concurrent GC operations. These set up logging, monitoring 396 // for concurrent operation. 397 void entry_reset(); 398 void entry_mark(); 399 void entry_preclean(); 400 void entry_weak_roots(); 401 void entry_class_unloading(); 402 void entry_strong_roots(); 403 void entry_cleanup_early(); 404 void entry_evac(); 405 void entry_updaterefs(); 406 void entry_cleanup_complete(); 407 void entry_uncommit(double shrink_before); 408 409 private: 410 // Actual work for the phases 411 void op_init_mark(); 412 void op_final_mark(); 413 void op_init_updaterefs(); 414 void op_final_updaterefs(); 415 void op_full(GCCause::Cause cause); 416 void op_degenerated(ShenandoahDegenPoint point); 417 void op_degenerated_fail(); 418 void op_degenerated_futile(); 419 420 void op_reset(); 421 void op_mark(); 422 void op_preclean(); 423 void op_weak_roots(); 424 void op_class_unloading(); 425 void op_strong_roots(); 426 void op_cleanup_early(); 427 void op_conc_evac(); 428 void op_stw_evac(); 429 void op_updaterefs(); 430 void op_cleanup_complete(); 431 void op_uncommit(double shrink_before); 432 433 // Messages for GC trace events, they have to be immortal for 434 // passing around the logging/tracing systems 435 const char* init_mark_event_message() const; 436 const char* final_mark_event_message() const; 437 const char* conc_mark_event_message() const; 438 const char* degen_event_message(ShenandoahDegenPoint point) const; 439 440 // ---------- GC subsystems 441 // 442 private: 443 ShenandoahControlThread* _control_thread; 444 ShenandoahCollectorPolicy* _shenandoah_policy; 445 ShenandoahMode* _gc_mode; 446 ShenandoahHeuristics* _heuristics; 447 ShenandoahFreeSet* _free_set; 448 ShenandoahConcurrentMark* _scm; 449 ShenandoahMarkCompact* _full_gc; 450 ShenandoahPacer* _pacer; 451 ShenandoahVerifier* _verifier; 452 453 ShenandoahPhaseTimings* _phase_timings; 454 455 ShenandoahControlThread* control_thread() { return _control_thread; } 456 ShenandoahMarkCompact* full_gc() { return _full_gc; } 457 458 public: 459 ShenandoahCollectorPolicy* shenandoah_policy() const { return _shenandoah_policy; } 460 ShenandoahHeuristics* heuristics() const { return _heuristics; } 461 ShenandoahFreeSet* free_set() const { return _free_set; } 462 ShenandoahConcurrentMark* concurrent_mark() { return _scm; } 463 ShenandoahPacer* pacer() const { return _pacer; } 464 465 ShenandoahPhaseTimings* phase_timings() const { return _phase_timings; } 466 467 ShenandoahVerifier* verifier(); 468 469 // ---------- VM subsystem bindings 470 // 471 private: 472 ShenandoahMonitoringSupport* _monitoring_support; 473 MemoryPool* _memory_pool; 474 GCMemoryManager _stw_memory_manager; 475 GCMemoryManager _cycle_memory_manager; 476 ConcurrentGCTimer* _gc_timer; 477 SoftRefPolicy _soft_ref_policy; 478 479 // For exporting to SA 480 int _log_min_obj_alignment_in_bytes; 481 public: 482 ShenandoahMonitoringSupport* monitoring_support() { return _monitoring_support; } 483 GCMemoryManager* cycle_memory_manager() { return &_cycle_memory_manager; } 484 GCMemoryManager* stw_memory_manager() { return &_stw_memory_manager; } 485 SoftRefPolicy* soft_ref_policy() { return &_soft_ref_policy; } 486 487 GrowableArray<GCMemoryManager*> memory_managers(); 488 GrowableArray<MemoryPool*> memory_pools(); 489 MemoryUsage memory_usage(); 490 GCTracer* tracer(); 491 ConcurrentGCTimer* gc_timer() const; 492 493 // ---------- Reference processing 494 // 495 private: 496 AlwaysTrueClosure _subject_to_discovery; 497 ReferenceProcessor* _ref_processor; 498 ShenandoahSharedFlag _process_references; 499 500 void ref_processing_init(); 501 502 public: 503 ReferenceProcessor* ref_processor() { return _ref_processor; } 504 void set_process_references(bool pr); 505 bool process_references() const; 506 507 // ---------- Class Unloading 508 // 509 private: 510 ShenandoahSharedFlag _unload_classes; 511 ShenandoahUnload _unloader; 512 513 public: 514 void set_unload_classes(bool uc); 515 bool unload_classes() const; 516 517 // Perform STW class unloading and weak root cleaning 518 void parallel_cleaning(bool full_gc); 519 520 private: 521 void stw_unload_classes(bool full_gc); 522 void stw_process_weak_roots(bool full_gc); 523 524 // Prepare concurrent root processing 525 void prepare_concurrent_roots(); 526 // Prepare and finish concurrent unloading 527 void prepare_concurrent_unloading(); 528 void finish_concurrent_unloading(); 529 530 // ---------- Generic interface hooks 531 // Minor things that super-interface expects us to implement to play nice with 532 // the rest of runtime. Some of the things here are not required to be implemented, 533 // and can be stubbed out. 534 // 535 public: 536 AdaptiveSizePolicy* size_policy() shenandoah_not_implemented_return(NULL); 537 bool is_maximal_no_gc() const shenandoah_not_implemented_return(false); 538 539 bool is_in(const void* p) const; 540 541 MemRegion reserved_region() const { return _reserved; } 542 bool is_in_reserved(const void* addr) const { return _reserved.contains(addr); } 543 544 void collect(GCCause::Cause cause); 545 void do_full_collection(bool clear_all_soft_refs); 546 547 // Used for parsing heap during error printing 548 HeapWord* block_start(const void* addr) const; 549 bool block_is_obj(const HeapWord* addr) const; 550 bool print_location(outputStream* st, void* addr) const; 551 552 // Used for native heap walkers: heap dumpers, mostly 553 void object_iterate(ObjectClosure* cl); 554 555 // Keep alive an object that was loaded with AS_NO_KEEPALIVE. 556 void keep_alive(oop obj); 557 558 // Used by RMI 559 jlong millis_since_last_gc(); 560 561 // ---------- Safepoint interface hooks 562 // 563 public: 564 void safepoint_synchronize_begin(); 565 void safepoint_synchronize_end(); 566 567 // ---------- Code roots handling hooks 568 // 569 public: 570 void register_nmethod(nmethod* nm); 571 void unregister_nmethod(nmethod* nm); 572 void flush_nmethod(nmethod* nm); 573 void verify_nmethod(nmethod* nm) {} 574 575 // ---------- Pinning hooks 576 // 577 public: 578 // Shenandoah supports per-object (per-region) pinning 579 bool supports_object_pinning() const { return true; } 580 581 oop pin_object(JavaThread* thread, oop obj); 582 void unpin_object(JavaThread* thread, oop obj); 583 584 void sync_pinned_region_status(); 585 void assert_pinned_region_status() NOT_DEBUG_RETURN; 586 587 // ---------- Allocation support 588 // 589 private: 590 HeapWord* allocate_memory_under_lock(ShenandoahAllocRequest& request, bool& in_new_region); 591 inline HeapWord* allocate_from_gclab(Thread* thread, size_t size); 592 HeapWord* allocate_from_gclab_slow(Thread* thread, size_t size); 593 HeapWord* allocate_new_gclab(size_t min_size, size_t word_size, size_t* actual_size); 594 void retire_and_reset_gclabs(); 595 596 public: 597 HeapWord* allocate_memory(ShenandoahAllocRequest& request); 598 HeapWord* mem_allocate(size_t size, bool* what); 599 MetaWord* satisfy_failed_metadata_allocation(ClassLoaderData* loader_data, 600 size_t size, 601 Metaspace::MetadataType mdtype); 602 603 void notify_mutator_alloc_words(size_t words, bool waste); 604 605 // Shenandoah supports TLAB allocation 606 bool supports_tlab_allocation() const { return true; } 607 608 HeapWord* allocate_new_tlab(size_t min_size, size_t requested_size, size_t* actual_size); 609 size_t tlab_capacity(Thread *thr) const; 610 size_t unsafe_max_tlab_alloc(Thread *thread) const; 611 size_t max_tlab_size() const; 612 size_t tlab_used(Thread* ignored) const; 613 614 void resize_tlabs(); 615 616 void ensure_parsability(bool retire_tlabs); 617 void make_parsable(bool retire_tlabs); 618 619 // ---------- Marking support 620 // 621 private: 622 ShenandoahMarkingContext* _marking_context; 623 MemRegion _bitmap_region; 624 MemRegion _aux_bitmap_region; 625 MarkBitMap _verification_bit_map; 626 MarkBitMap _aux_bit_map; 627 628 size_t _bitmap_size; 629 size_t _bitmap_regions_per_slice; 630 size_t _bitmap_bytes_per_slice; 631 632 size_t _pretouch_heap_page_size; 633 size_t _pretouch_bitmap_page_size; 634 635 bool _bitmap_region_special; 636 bool _aux_bitmap_region_special; 637 638 ShenandoahLiveData** _liveness_cache; 639 640 public: 641 inline ShenandoahMarkingContext* complete_marking_context() const; 642 inline ShenandoahMarkingContext* marking_context() const; 643 inline void mark_complete_marking_context(); 644 inline void mark_incomplete_marking_context(); 645 646 template<class T> 647 inline void marked_object_iterate(ShenandoahHeapRegion* region, T* cl); 648 649 template<class T> 650 inline void marked_object_iterate(ShenandoahHeapRegion* region, T* cl, HeapWord* limit); 651 652 template<class T> 653 inline void marked_object_oop_iterate(ShenandoahHeapRegion* region, T* cl, HeapWord* limit); 654 655 void reset_mark_bitmap(); 656 657 // SATB barriers hooks 658 template<bool RESOLVE> 659 inline bool requires_marking(const void* entry) const; 660 void force_satb_flush_all_threads(); 661 662 // Support for bitmap uncommits 663 bool commit_bitmap_slice(ShenandoahHeapRegion *r); 664 bool uncommit_bitmap_slice(ShenandoahHeapRegion *r); 665 bool is_bitmap_slice_committed(ShenandoahHeapRegion* r, bool skip_self = false); 666 667 // Liveness caching support 668 ShenandoahLiveData* get_liveness_cache(uint worker_id); 669 void flush_liveness_cache(uint worker_id); 670 671 size_t pretouch_heap_page_size() { return _pretouch_heap_page_size; } 672 673 // ---------- Evacuation support 674 // 675 private: 676 ShenandoahCollectionSet* _collection_set; 677 ShenandoahEvacOOMHandler _oom_evac_handler; 678 679 void evacuate_and_update_roots(); 680 681 public: 682 static address in_cset_fast_test_addr(); 683 684 ShenandoahCollectionSet* collection_set() const { return _collection_set; } 685 686 // Checks if object is in the collection set. 687 inline bool in_collection_set(oop obj) const; 688 689 // Checks if location is in the collection set. Can be interior pointer, not the oop itself. 690 inline bool in_collection_set_loc(void* loc) const; 691 692 // Evacuates object src. Returns the evacuated object, either evacuated 693 // by this thread, or by some other thread. 694 inline oop evacuate_object(oop src, Thread* thread); 695 696 // Call before/after evacuation. 697 void enter_evacuation(); 698 void leave_evacuation(); 699 700 // ---------- Helper functions 701 // 702 public: 703 template <class T> 704 inline oop evac_update_with_forwarded(T* p); 705 706 template <class T> 707 inline oop maybe_update_with_forwarded(T* p); 708 709 template <class T> 710 inline oop maybe_update_with_forwarded_not_null(T* p, oop obj); 711 712 template <class T> 713 inline oop update_with_forwarded_not_null(T* p, oop obj); 714 715 static inline oop cas_oop(oop n, narrowOop* addr, oop c); 716 static inline oop cas_oop(oop n, oop* addr, oop c); 717 static inline oop cas_oop(oop n, narrowOop* addr, narrowOop c); 718 719 void trash_humongous_region_at(ShenandoahHeapRegion *r); 720 721 void deduplicate_string(oop str); 722 723 private: 724 void trash_cset_regions(); 725 void update_heap_references(bool concurrent); 726 727 // ---------- Testing helpers functions 728 // 729 private: 730 ShenandoahSharedFlag _inject_alloc_failure; 731 732 void try_inject_alloc_failure(); 733 bool should_inject_alloc_failure(); 734 }; 735 736 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHHEAP_HPP