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