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