1 /* 2 * Copyright (c) 2017, 2021, Oracle and/or its affiliates. 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_G1_G1FULLCOLLECTOR_HPP 26 #define SHARE_GC_G1_G1FULLCOLLECTOR_HPP 27 28 #include "gc/g1/g1FullGCCompactionPoint.hpp" 29 #include "gc/g1/g1FullGCHeapRegionAttr.hpp" 30 #include "gc/g1/g1FullGCMarker.hpp" 31 #include "gc/g1/g1FullGCOopClosures.hpp" 32 #include "gc/g1/g1FullGCScope.hpp" 33 #include "gc/g1/g1RegionMarkStatsCache.hpp" 34 #include "gc/shared/preservedMarks.hpp" 35 #include "gc/shared/referenceProcessor.hpp" 36 #include "gc/shared/taskqueue.hpp" 37 #include "memory/allocation.hpp" 38 #include "oops/oopsHierarchy.hpp" 39 40 class AbstractGangTask; 41 class G1CMBitMap; 42 class G1FullGCMarker; 43 class G1FullGCScope; 44 class G1FullGCCompactionPoint; 45 class GCMemoryManager; 46 class ReferenceProcessor; 47 48 // Subject-to-discovery closure for reference processing during Full GC. During 49 // Full GC the whole heap is subject to discovery. 50 class G1FullGCSubjectToDiscoveryClosure: public BoolObjectClosure { 51 public: do_object_b(oop p)52 bool do_object_b(oop p) { 53 assert(p != NULL, "must be"); 54 return true; 55 } 56 }; 57 58 // The G1FullCollector holds data associated with the current Full GC. 59 class G1FullCollector : StackObj { 60 G1CollectedHeap* _heap; 61 G1FullGCScope _scope; 62 uint _num_workers; 63 G1FullGCMarker** _markers; 64 G1FullGCCompactionPoint** _compaction_points; 65 OopQueueSet _oop_queue_set; 66 ObjArrayTaskQueueSet _array_queue_set; 67 PreservedMarksSet _preserved_marks_set; 68 G1FullGCCompactionPoint _serial_compaction_point; 69 G1IsAliveClosure _is_alive; 70 ReferenceProcessorIsAliveMutator _is_alive_mutator; 71 G1RegionMarkStats* _live_stats; 72 73 static uint calc_active_workers(); 74 75 G1FullGCSubjectToDiscoveryClosure _always_subject_to_discovery; 76 ReferenceProcessorSubjectToDiscoveryMutator _is_subject_mutator; 77 78 G1FullGCHeapRegionAttr _region_attr_table; 79 80 public: 81 G1FullCollector(G1CollectedHeap* heap, 82 bool explicit_gc, 83 bool clear_soft_refs, 84 bool do_maximum_compaction); 85 ~G1FullCollector(); 86 87 void prepare_collection(); 88 void collect(); 89 void complete_collection(); 90 scope()91 G1FullGCScope* scope() { return &_scope; } workers()92 uint workers() { return _num_workers; } marker(uint id)93 G1FullGCMarker* marker(uint id) { return _markers[id]; } compaction_point(uint id)94 G1FullGCCompactionPoint* compaction_point(uint id) { return _compaction_points[id]; } oop_queue_set()95 OopQueueSet* oop_queue_set() { return &_oop_queue_set; } array_queue_set()96 ObjArrayTaskQueueSet* array_queue_set() { return &_array_queue_set; } preserved_mark_set()97 PreservedMarksSet* preserved_mark_set() { return &_preserved_marks_set; } serial_compaction_point()98 G1FullGCCompactionPoint* serial_compaction_point() { return &_serial_compaction_point; } 99 G1CMBitMap* mark_bitmap(); 100 ReferenceProcessor* reference_processor(); live_words(uint region_index)101 size_t live_words(uint region_index) { 102 assert(region_index < _heap->max_regions(), "sanity"); 103 return _live_stats[region_index]._live_words; 104 } 105 106 void before_marking_update_attribute_table(HeapRegion* hr); 107 108 inline bool is_compacting(oop obj) const; 109 inline bool is_skip_compacting(uint region_index) const; 110 inline bool is_skip_marking(oop obj) const; 111 112 inline void set_invalid(uint region_idx); 113 inline void update_from_compacting_to_skip_compacting(uint region_idx); 114 115 private: 116 void phase1_mark_live_objects(); 117 void phase2_prepare_compaction(); 118 void phase3_adjust_pointers(); 119 void phase4_do_compaction(); 120 121 void restore_marks(); 122 void verify_after_marking(); 123 124 void run_task(AbstractGangTask* task); 125 }; 126 127 128 #endif // SHARE_GC_G1_G1FULLCOLLECTOR_HPP 129