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/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 virtual void heap_region_do(ShenandoahHeapRegion* r) = 0; 91 virtual bool is_thread_safe() { return false; } 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() NOT_DEBUG_RETURN; 167 void assert_heaplock_not_owned_by_current_thread() NOT_DEBUG_RETURN; 168 void assert_heaplock_or_safepoint() NOT_DEBUG_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) NOT_DEBUG_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) const; 258 void parallel_heap_region_iterate(ShenandoahHeapRegionClosure* blk) const; 259 260 // ---------- GC state machinery 261 // 262 // GC state describes the important parts of collector state, that may be 263 // used to make barrier selection decisions in the native and generated code. 264 // Multiple bits can be set at once. 265 // 266 // Important invariant: when GC state is zero, the heap is stable, and no barriers 267 // are required. 268 // 269 public: 270 enum GCStateBitPos { 271 // Heap has forwarded objects: need RB, ACMP, CAS barriers. 272 HAS_FORWARDED_BITPOS = 0, 273 274 // Heap is under marking: needs SATB barriers. 275 MARKING_BITPOS = 1, 276 277 // Heap is under evacuation: needs WB barriers. (Set together with UNSTABLE) 278 EVACUATION_BITPOS = 2, 279 280 // Heap is under updating: needs SVRB/SVWB barriers. 281 UPDATEREFS_BITPOS = 3, 282 283 // Heap is under traversal collection 284 TRAVERSAL_BITPOS = 4, 285 }; 286 287 enum GCState { 288 STABLE = 0, 289 HAS_FORWARDED = 1 << HAS_FORWARDED_BITPOS, 290 MARKING = 1 << MARKING_BITPOS, 291 EVACUATION = 1 << EVACUATION_BITPOS, 292 UPDATEREFS = 1 << UPDATEREFS_BITPOS, 293 TRAVERSAL = 1 << TRAVERSAL_BITPOS, 294 }; 295 296 private: 297 ShenandoahSharedBitmap _gc_state; 298 ShenandoahSharedFlag _degenerated_gc_in_progress; 299 ShenandoahSharedFlag _full_gc_in_progress; 300 ShenandoahSharedFlag _full_gc_move_in_progress; 301 ShenandoahSharedFlag _progress_last_gc; 302 303 void set_gc_state_all_threads(char state); 304 void set_gc_state_mask(uint mask, bool value); 305 306 public: 307 char gc_state() const; 308 static address gc_state_addr(); 309 310 void set_concurrent_mark_in_progress(bool in_progress); 311 void set_evacuation_in_progress(bool in_progress); 312 void set_update_refs_in_progress(bool in_progress); 313 void set_degenerated_gc_in_progress(bool in_progress); 314 void set_full_gc_in_progress(bool in_progress); 315 void set_full_gc_move_in_progress(bool in_progress); 316 void set_concurrent_traversal_in_progress(bool in_progress); 317 void set_has_forwarded_objects(bool cond); 318 319 inline bool is_stable() const; 320 inline bool is_idle() const; 321 inline bool is_concurrent_mark_in_progress() const; 322 inline bool is_update_refs_in_progress() const; 323 inline bool is_evacuation_in_progress() const; 324 inline bool is_degenerated_gc_in_progress() const; 325 inline bool is_full_gc_in_progress() const; 326 inline bool is_full_gc_move_in_progress() const; 327 inline bool is_concurrent_traversal_in_progress() const; 328 inline bool has_forwarded_objects() const; 329 inline bool is_gc_in_progress_mask(uint mask) const; 330 331 // ---------- GC cancellation and degeneration machinery 332 // 333 // Cancelled GC flag is used to notify concurrent phases that they should terminate. 334 // 335 public: 336 enum ShenandoahDegenPoint { 337 _degenerated_unset, 338 _degenerated_traversal, 339 _degenerated_outside_cycle, 340 _degenerated_mark, 341 _degenerated_evac, 342 _degenerated_updaterefs, 343 _DEGENERATED_LIMIT, 344 }; 345 346 static const char* degen_point_to_string(ShenandoahDegenPoint point) { 347 switch (point) { 348 case _degenerated_unset: 349 return "<UNSET>"; 350 case _degenerated_traversal: 351 return "Traversal"; 352 case _degenerated_outside_cycle: 353 return "Outside of Cycle"; 354 case _degenerated_mark: 355 return "Mark"; 356 case _degenerated_evac: 357 return "Evacuation"; 358 case _degenerated_updaterefs: 359 return "Update Refs"; 360 default: 361 ShouldNotReachHere(); 362 return "ERROR"; 363 } 364 }; 365 366 private: 367 enum CancelState { 368 // Normal state. GC has not been cancelled and is open for cancellation. 369 // Worker threads can suspend for safepoint. 370 CANCELLABLE, 371 372 // GC has been cancelled. Worker threads can not suspend for 373 // safepoint but must finish their work as soon as possible. 374 CANCELLED, 375 376 // GC has not been cancelled and must not be cancelled. At least 377 // one worker thread checks for pending safepoint and may suspend 378 // if a safepoint is pending. 379 NOT_CANCELLED 380 }; 381 382 ShenandoahSharedEnumFlag<CancelState> _cancelled_gc; 383 bool try_cancel_gc(); 384 385 public: 386 static address cancelled_gc_addr(); 387 388 inline bool cancelled_gc() const; 389 inline bool check_cancelled_gc_and_yield(bool sts_active = true); 390 391 inline void clear_cancelled_gc(); 392 393 void cancel_gc(GCCause::Cause cause); 394 395 // ---------- GC operations entry points 396 // 397 public: 398 // Entry points to STW GC operations, these cause a related safepoint, that then 399 // call the entry method below 400 void vmop_entry_init_mark(); 401 void vmop_entry_final_mark(); 402 void vmop_entry_final_evac(); 403 void vmop_entry_init_updaterefs(); 404 void vmop_entry_final_updaterefs(); 405 void vmop_entry_init_traversal(); 406 void vmop_entry_final_traversal(); 407 void vmop_entry_full(GCCause::Cause cause); 408 void vmop_degenerated(ShenandoahDegenPoint point); 409 410 // Entry methods to normally STW GC operations. These set up logging, monitoring 411 // and workers for net VM operation 412 void entry_init_mark(); 413 void entry_final_mark(); 414 void entry_final_evac(); 415 void entry_init_updaterefs(); 416 void entry_final_updaterefs(); 417 void entry_init_traversal(); 418 void entry_final_traversal(); 419 void entry_full(GCCause::Cause cause); 420 void entry_degenerated(int point); 421 422 // Entry methods to normally concurrent GC operations. These set up logging, monitoring 423 // for concurrent operation. 424 void entry_reset(); 425 void entry_mark(); 426 void entry_preclean(); 427 void entry_cleanup(); 428 void entry_evac(); 429 void entry_updaterefs(); 430 void entry_traversal(); 431 void entry_uncommit(double shrink_before); 432 433 private: 434 // Actual work for the phases 435 void op_init_mark(); 436 void op_final_mark(); 437 void op_final_evac(); 438 void op_init_updaterefs(); 439 void op_final_updaterefs(); 440 void op_init_traversal(); 441 void op_final_traversal(); 442 void op_full(GCCause::Cause cause); 443 void op_degenerated(ShenandoahDegenPoint point); 444 void op_degenerated_fail(); 445 void op_degenerated_futile(); 446 447 void op_reset(); 448 void op_mark(); 449 void op_preclean(); 450 void op_cleanup(); 451 void op_conc_evac(); 452 void op_stw_evac(); 453 void op_updaterefs(); 454 void op_traversal(); 455 void op_uncommit(double shrink_before); 456 457 // Messages for GC trace events, they have to be immortal for 458 // passing around the logging/tracing systems 459 const char* init_mark_event_message() const; 460 const char* final_mark_event_message() const; 461 const char* conc_mark_event_message() const; 462 const char* degen_event_message(ShenandoahDegenPoint point) const; 463 464 // ---------- GC subsystems 465 // 466 private: 467 ShenandoahControlThread* _control_thread; 468 ShenandoahCollectorPolicy* _shenandoah_policy; 469 ShenandoahHeuristics* _heuristics; 470 ShenandoahFreeSet* _free_set; 471 ShenandoahConcurrentMark* _scm; 472 ShenandoahTraversalGC* _traversal_gc; 473 ShenandoahMarkCompact* _full_gc; 474 ShenandoahPacer* _pacer; 475 ShenandoahVerifier* _verifier; 476 477 ShenandoahAllocTracker* _alloc_tracker; 478 ShenandoahPhaseTimings* _phase_timings; 479 480 ShenandoahControlThread* control_thread() { return _control_thread; } 481 ShenandoahMarkCompact* full_gc() { return _full_gc; } 482 483 public: 484 ShenandoahCollectorPolicy* shenandoah_policy() const { return _shenandoah_policy; } 485 ShenandoahHeuristics* heuristics() const { return _heuristics; } 486 ShenandoahFreeSet* free_set() const { return _free_set; } 487 ShenandoahConcurrentMark* concurrent_mark() { return _scm; } 488 ShenandoahTraversalGC* traversal_gc() { return _traversal_gc; } 489 ShenandoahPacer* pacer() const { return _pacer; } 490 491 ShenandoahPhaseTimings* phase_timings() const { return _phase_timings; } 492 ShenandoahAllocTracker* alloc_tracker() const { return _alloc_tracker; } 493 494 ShenandoahVerifier* verifier(); 495 496 // ---------- VM subsystem bindings 497 // 498 private: 499 ShenandoahMonitoringSupport* _monitoring_support; 500 MemoryPool* _memory_pool; 501 GCMemoryManager _stw_memory_manager; 502 GCMemoryManager _cycle_memory_manager; 503 ConcurrentGCTimer* _gc_timer; 504 SoftRefPolicy _soft_ref_policy; 505 506 public: 507 ShenandoahMonitoringSupport* monitoring_support() { return _monitoring_support; } 508 GCMemoryManager* cycle_memory_manager() { return &_cycle_memory_manager; } 509 GCMemoryManager* stw_memory_manager() { return &_stw_memory_manager; } 510 SoftRefPolicy* soft_ref_policy() { return &_soft_ref_policy; } 511 512 GrowableArray<GCMemoryManager*> memory_managers(); 513 GrowableArray<MemoryPool*> memory_pools(); 514 MemoryUsage memory_usage(); 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 virtual ptrdiff_t cell_header_size() const; 559 560 // All objects can potentially move 561 bool is_scavengable(oop obj) { return true; }; 562 563 void collect(GCCause::Cause cause); 564 void do_full_collection(bool clear_all_soft_refs); 565 566 // Used for parsing heap during error printing 567 HeapWord* block_start(const void* addr) const; 568 size_t block_size(const HeapWord* addr) const; 569 bool block_is_obj(const HeapWord* addr) const; 570 571 // Used for native heap walkers: heap dumpers, mostly 572 void object_iterate(ObjectClosure* cl); 573 void safe_object_iterate(ObjectClosure* cl); 574 575 // Used by RMI 576 jlong millis_since_last_gc(); 577 578 // ---------- Safepoint interface hooks 579 // 580 public: 581 void safepoint_synchronize_begin(); 582 void safepoint_synchronize_end(); 583 584 // ---------- Code roots handling hooks 585 // 586 public: 587 void register_nmethod(nmethod* nm); 588 void unregister_nmethod(nmethod* nm); 589 590 // ---------- Pinning hooks 591 // 592 public: 593 // Shenandoah supports per-object (per-region) pinning 594 bool supports_object_pinning() const { return true; } 595 596 oop pin_object(JavaThread* thread, oop obj); 597 void unpin_object(JavaThread* thread, oop obj); 598 599 // ---------- Allocation support 600 // 601 private: 602 HeapWord* allocate_memory_under_lock(ShenandoahAllocRequest& request, bool& in_new_region); 603 inline HeapWord* allocate_from_gclab(Thread* thread, size_t size); 604 HeapWord* allocate_from_gclab_slow(Thread* thread, size_t size); 605 HeapWord* allocate_new_gclab(size_t min_size, size_t word_size, size_t* actual_size); 606 void retire_and_reset_gclabs(); 607 608 public: 609 HeapWord* allocate_memory(ShenandoahAllocRequest& request); 610 HeapWord* mem_allocate(size_t size, bool* what); 611 MetaWord* satisfy_failed_metadata_allocation(ClassLoaderData* loader_data, 612 size_t size, 613 Metaspace::MetadataType mdtype); 614 615 oop obj_allocate(Klass* klass, int size, TRAPS); 616 oop array_allocate(Klass* klass, int size, int length, bool do_zero, TRAPS); 617 oop class_allocate(Klass* klass, int size, TRAPS); 618 619 void notify_mutator_alloc_words(size_t words, bool waste); 620 621 // Shenandoah supports TLAB allocation 622 bool supports_tlab_allocation() const { return true; } 623 624 HeapWord* allocate_new_tlab(size_t min_size, size_t requested_size, size_t* actual_size); 625 size_t tlab_capacity(Thread *thr) const; 626 size_t unsafe_max_tlab_alloc(Thread *thread) const; 627 size_t max_tlab_size() const; 628 size_t tlab_used(Thread* ignored) const; 629 630 HeapWord* tlab_post_allocation_setup(HeapWord* obj); 631 void fill_with_dummy_object(HeapWord* start, HeapWord* end, bool zap); 632 size_t min_dummy_object_size() const; 633 634 void resize_tlabs(); 635 636 void ensure_parsability(bool retire_tlabs); 637 void make_parsable(bool retire_tlabs); 638 639 // ---------- Marking support 640 // 641 private: 642 ShenandoahMarkingContext* _marking_context; 643 MemRegion _bitmap_region; 644 MemRegion _aux_bitmap_region; 645 MarkBitMap _verification_bit_map; 646 MarkBitMap _aux_bit_map; 647 648 size_t _bitmap_size; 649 size_t _bitmap_regions_per_slice; 650 size_t _bitmap_bytes_per_slice; 651 652 // Used for buffering per-region liveness data. 653 // Needed since ShenandoahHeapRegion uses atomics to update liveness. 654 // 655 // The array has max-workers elements, each of which is an array of 656 // jushort * max_regions. The choice of jushort is not accidental: 657 // there is a tradeoff between static/dynamic footprint that translates 658 // into cache pressure (which is already high during marking), and 659 // too many atomic updates. size_t/jint is too large, jbyte is too small. 660 jushort** _liveness_cache; 661 662 public: 663 inline ShenandoahMarkingContext* complete_marking_context() const; 664 inline ShenandoahMarkingContext* marking_context() const; 665 inline void mark_complete_marking_context(); 666 inline void mark_incomplete_marking_context(); 667 668 template<class T> 669 inline void marked_object_iterate(ShenandoahHeapRegion* region, T* cl); 670 671 template<class T> 672 inline void marked_object_iterate(ShenandoahHeapRegion* region, T* cl, HeapWord* limit); 673 674 template<class T> 675 inline void marked_object_oop_iterate(ShenandoahHeapRegion* region, T* cl, HeapWord* limit); 676 677 void reset_mark_bitmap(); 678 679 // SATB barriers hooks 680 template<bool RESOLVE> 681 inline bool requires_marking(const void* entry) const; 682 void force_satb_flush_all_threads(); 683 684 // Support for bitmap uncommits 685 bool commit_bitmap_slice(ShenandoahHeapRegion *r); 686 bool uncommit_bitmap_slice(ShenandoahHeapRegion *r); 687 bool is_bitmap_slice_committed(ShenandoahHeapRegion* r, bool skip_self = false); 688 689 // Liveness caching support 690 jushort* get_liveness_cache(uint worker_id); 691 void flush_liveness_cache(uint worker_id); 692 693 // ---------- Evacuation support 694 // 695 private: 696 ShenandoahCollectionSet* _collection_set; 697 ShenandoahEvacOOMHandler _oom_evac_handler; 698 699 void evacuate_and_update_roots(); 700 701 public: 702 static address in_cset_fast_test_addr(); 703 704 ShenandoahCollectionSet* collection_set() const { return _collection_set; } 705 706 template <class T> 707 inline bool in_collection_set(T obj) const; 708 709 // Avoid accidentally calling the method above with ShenandoahHeapRegion*, which would be *wrong*. 710 inline bool in_collection_set(ShenandoahHeapRegion* r) shenandoah_not_implemented_return(false); 711 712 // Evacuates object src. Returns the evacuated object, either evacuated 713 // by this thread, or by some other thread. 714 inline oop evacuate_object(oop src, Thread* thread); 715 716 // Call before/after evacuation. 717 void enter_evacuation(); 718 void leave_evacuation(); 719 720 // ---------- Helper functions 721 // 722 public: 723 template <class T> 724 inline oop evac_update_with_forwarded(T* p); 725 726 template <class T> 727 inline oop maybe_update_with_forwarded(T* p); 728 729 template <class T> 730 inline oop maybe_update_with_forwarded_not_null(T* p, oop obj); 731 732 template <class T> 733 inline oop update_with_forwarded_not_null(T* p, oop obj); 734 735 inline oop atomic_compare_exchange_oop(oop n, narrowOop* addr, oop c); 736 inline oop atomic_compare_exchange_oop(oop n, oop* addr, oop c); 737 738 void trash_humongous_region_at(ShenandoahHeapRegion *r); 739 740 void deduplicate_string(oop str); 741 742 void stop_concurrent_marking(); 743 744 void roots_iterate(OopClosure* cl); 745 746 private: 747 void trash_cset_regions(); 748 void update_heap_references(bool concurrent); 749 750 // ---------- Testing helpers functions 751 // 752 private: 753 ShenandoahSharedFlag _inject_alloc_failure; 754 755 void try_inject_alloc_failure(); 756 bool should_inject_alloc_failure(); 757 }; 758 759 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHHEAP_HPP