40 #include "gc/g1/hSpaceCounters.hpp"
41 #include "gc/g1/heapRegionManager.hpp"
42 #include "gc/g1/heapRegionSet.hpp"
43 #include "gc/shared/barrierSet.hpp"
44 #include "gc/shared/collectedHeap.hpp"
45 #include "memory/memRegion.hpp"
46 #include "utilities/stack.hpp"
47
48 // A "G1CollectedHeap" is an implementation of a java heap for HotSpot.
49 // It uses the "Garbage First" heap organization and algorithm, which
50 // may combine concurrent marking with parallel, incremental compaction of
51 // heap subsets that will yield large amounts of garbage.
52
53 // Forward declarations
54 class HeapRegion;
55 class HRRSCleanupTask;
56 class GenerationSpec;
57 class OopsInHeapRegionClosure;
58 class G1KlassScanClosure;
59 class G1ParScanThreadState;
60 class ObjectClosure;
61 class SpaceClosure;
62 class CompactibleSpaceClosure;
63 class Space;
64 class G1CollectorPolicy;
65 class GenRemSet;
66 class G1RemSet;
67 class HeapRegionRemSetIterator;
68 class ConcurrentMark;
69 class ConcurrentMarkThread;
70 class ConcurrentG1Refine;
71 class ConcurrentGCTimer;
72 class GenerationCounters;
73 class STWGCTimer;
74 class G1NewTracer;
75 class G1OldTracer;
76 class EvacuationFailedInfo;
77 class nmethod;
78 class Ticks;
79 class FlexibleWorkGang;
152 HeapRegion* last_survivor_region() { return _survivor_tail; }
153
154 // debugging
155 bool check_list_well_formed();
156 bool check_list_empty(bool check_sample = true);
157 void print();
158 };
159
160 // The G1 STW is alive closure.
161 // An instance is embedded into the G1CH and used as the
162 // (optional) _is_alive_non_header closure in the STW
163 // reference processor. It is also extensively used during
164 // reference processing during STW evacuation pauses.
165 class G1STWIsAliveClosure: public BoolObjectClosure {
166 G1CollectedHeap* _g1;
167 public:
168 G1STWIsAliveClosure(G1CollectedHeap* g1) : _g1(g1) {}
169 bool do_object_b(oop p);
170 };
171
172 class RefineCardTableEntryClosure;
173
174 class G1RegionMappingChangedListener : public G1MappingChangedListener {
175 private:
176 void reset_from_card_cache(uint start_idx, size_t num_regions);
177 public:
178 virtual void on_commit(uint start_idx, size_t num_regions, bool zero_filled);
179 };
180
181 class G1CollectedHeap : public CollectedHeap {
182 friend class VM_CollectForMetadataAllocation;
183 friend class VM_G1CollectForAllocation;
184 friend class VM_G1CollectFull;
185 friend class VM_G1IncCollectionPause;
186 friend class VMStructs;
187 friend class MutatorAllocRegion;
188 friend class SurvivorGCAllocRegion;
189 friend class OldGCAllocRegion;
190 friend class G1Allocator;
191 friend class G1ArchiveAllocator;
192
814 bool* succeeded,
815 GCCause::Cause gc_cause);
816
817 void wait_for_root_region_scanning();
818
819 // The guts of the incremental collection pause, executed by the vm
820 // thread. It returns false if it is unable to do the collection due
821 // to the GC locker being active, true otherwise
822 bool do_collection_pause_at_safepoint(double target_pause_time_ms);
823
824 // Actually do the work of evacuating the collection set.
825 void evacuate_collection_set(EvacuationInfo& evacuation_info);
826
827 // The g1 remembered set of the heap.
828 G1RemSet* _g1_rem_set;
829
830 // A set of cards that cover the objects for which the Rsets should be updated
831 // concurrently after the collection.
832 DirtyCardQueueSet _dirty_card_queue_set;
833
834 // The closure used to refine a single card.
835 RefineCardTableEntryClosure* _refine_cte_cl;
836
837 // A DirtyCardQueueSet that is used to hold cards that contain
838 // references into the current collection set. This is used to
839 // update the remembered sets of the regions in the collection
840 // set in the event of an evacuation failure.
841 DirtyCardQueueSet _into_cset_dirty_card_queue_set;
842
843 // After a collection pause, make the regions in the CS into free
844 // regions.
845 void free_collection_set(HeapRegion* cs_head, EvacuationInfo& evacuation_info);
846
847 // Abandon the current collection set without recording policy
848 // statistics or updating free lists.
849 void abandon_collection_set(HeapRegion* cs_head);
850
851 // The concurrent marker (and the thread it runs in.)
852 ConcurrentMark* _cm;
853 ConcurrentMarkThread* _cmThread;
854
855 // The concurrent refiner.
1003 // _is_alive_non_header field. Supplying a value for the
1004 // _is_alive_non_header field is optional but doing so prevents
1005 // unnecessary additions to the discovered lists during reference
1006 // discovery.
1007 G1CMIsAliveClosure _is_alive_closure_cm;
1008
1009 // Cache used by G1CollectedHeap::start_cset_region_for_worker().
1010 HeapRegion** _worker_cset_start_region;
1011
1012 // Time stamp to validate the regions recorded in the cache
1013 // used by G1CollectedHeap::start_cset_region_for_worker().
1014 // The heap region entry for a given worker is valid iff
1015 // the associated time stamp value matches the current value
1016 // of G1CollectedHeap::_gc_time_stamp.
1017 uint* _worker_cset_start_region_time_stamp;
1018
1019 volatile bool _free_regions_coming;
1020
1021 public:
1022
1023 void set_refine_cte_cl_concurrency(bool concurrent);
1024
1025 RefToScanQueue *task_queue(uint i) const;
1026
1027 uint num_task_queues() const;
1028
1029 // A set of cards where updates happened during the GC
1030 DirtyCardQueueSet& dirty_card_queue_set() { return _dirty_card_queue_set; }
1031
1032 // A DirtyCardQueueSet that is used to hold cards that contain
1033 // references into the current collection set. This is used to
1034 // update the remembered sets of the regions in the collection
1035 // set in the event of an evacuation failure.
1036 DirtyCardQueueSet& into_cset_dirty_card_queue_set()
1037 { return _into_cset_dirty_card_queue_set; }
1038
1039 // Create a G1CollectedHeap with the specified policy.
1040 // Must call the initialize method afterwards.
1041 // May not return if something goes wrong.
1042 G1CollectedHeap(G1CollectorPolicy* policy);
|
40 #include "gc/g1/hSpaceCounters.hpp"
41 #include "gc/g1/heapRegionManager.hpp"
42 #include "gc/g1/heapRegionSet.hpp"
43 #include "gc/shared/barrierSet.hpp"
44 #include "gc/shared/collectedHeap.hpp"
45 #include "memory/memRegion.hpp"
46 #include "utilities/stack.hpp"
47
48 // A "G1CollectedHeap" is an implementation of a java heap for HotSpot.
49 // It uses the "Garbage First" heap organization and algorithm, which
50 // may combine concurrent marking with parallel, incremental compaction of
51 // heap subsets that will yield large amounts of garbage.
52
53 // Forward declarations
54 class HeapRegion;
55 class HRRSCleanupTask;
56 class GenerationSpec;
57 class OopsInHeapRegionClosure;
58 class G1KlassScanClosure;
59 class G1ParScanThreadState;
60 class GlobalSynchronizer;
61 class ObjectClosure;
62 class SpaceClosure;
63 class CompactibleSpaceClosure;
64 class Space;
65 class G1CollectorPolicy;
66 class GenRemSet;
67 class G1RemSet;
68 class HeapRegionRemSetIterator;
69 class ConcurrentMark;
70 class ConcurrentMarkThread;
71 class ConcurrentG1Refine;
72 class ConcurrentGCTimer;
73 class GenerationCounters;
74 class STWGCTimer;
75 class G1NewTracer;
76 class G1OldTracer;
77 class EvacuationFailedInfo;
78 class nmethod;
79 class Ticks;
80 class FlexibleWorkGang;
153 HeapRegion* last_survivor_region() { return _survivor_tail; }
154
155 // debugging
156 bool check_list_well_formed();
157 bool check_list_empty(bool check_sample = true);
158 void print();
159 };
160
161 // The G1 STW is alive closure.
162 // An instance is embedded into the G1CH and used as the
163 // (optional) _is_alive_non_header closure in the STW
164 // reference processor. It is also extensively used during
165 // reference processing during STW evacuation pauses.
166 class G1STWIsAliveClosure: public BoolObjectClosure {
167 G1CollectedHeap* _g1;
168 public:
169 G1STWIsAliveClosure(G1CollectedHeap* g1) : _g1(g1) {}
170 bool do_object_b(oop p);
171 };
172
173 class RefineCardTableEntryClosure: public CardTableEntryClosure {
174 public:
175 RefineCardTableEntryClosure() { }
176 bool do_card_ptr(jbyte* card_ptr, uint worker_i);
177 };
178
179 class CardBuffer : public CHeapObj<mtGC> {
180 public:
181 CardBuffer *_next;
182 GlobalSynchronizer *_gs;
183 jbyte **_card_buffer;
184 MemRegion *_mr_buffer;
185 int _length;
186
187 int _misses;
188
189 CardBuffer();
190 virtual ~CardBuffer();
191 };
192
193 class BufferedRefineCardTableEntryClosure: public CardTableEntryClosure {
194 CardBuffer *_head_buffer;
195 CardBuffer *_tail_buffer;
196 CardBuffer *_current_buffer;
197
198 int _index;
199 int _async_buffers;
200
201 uint _worker_i;
202 G1CollectedHeap *const _g1h;
203
204 bool pre_sync(CardBuffer *buffer, bool hard);
205 bool sync(CardBuffer *buffer, bool hard);
206 void post_sync(CardBuffer *buffer);
207
208 void general_flush(bool hard);
209 void soft_flush();
210 public:
211 BufferedRefineCardTableEntryClosure();
212 ~BufferedRefineCardTableEntryClosure();
213 static int buffer_size();
214 bool do_card_ptr(jbyte *card_ptr, uint worker_i);
215 void flush_buffer();
216 };
217
218
219 class G1RegionMappingChangedListener : public G1MappingChangedListener {
220 private:
221 void reset_from_card_cache(uint start_idx, size_t num_regions);
222 public:
223 virtual void on_commit(uint start_idx, size_t num_regions, bool zero_filled);
224 };
225
226 class G1CollectedHeap : public CollectedHeap {
227 friend class VM_CollectForMetadataAllocation;
228 friend class VM_G1CollectForAllocation;
229 friend class VM_G1CollectFull;
230 friend class VM_G1IncCollectionPause;
231 friend class VMStructs;
232 friend class MutatorAllocRegion;
233 friend class SurvivorGCAllocRegion;
234 friend class OldGCAllocRegion;
235 friend class G1Allocator;
236 friend class G1ArchiveAllocator;
237
859 bool* succeeded,
860 GCCause::Cause gc_cause);
861
862 void wait_for_root_region_scanning();
863
864 // The guts of the incremental collection pause, executed by the vm
865 // thread. It returns false if it is unable to do the collection due
866 // to the GC locker being active, true otherwise
867 bool do_collection_pause_at_safepoint(double target_pause_time_ms);
868
869 // Actually do the work of evacuating the collection set.
870 void evacuate_collection_set(EvacuationInfo& evacuation_info);
871
872 // The g1 remembered set of the heap.
873 G1RemSet* _g1_rem_set;
874
875 // A set of cards that cover the objects for which the Rsets should be updated
876 // concurrently after the collection.
877 DirtyCardQueueSet _dirty_card_queue_set;
878
879 bool _refine_cte_cl_concurrency;
880
881 // A DirtyCardQueueSet that is used to hold cards that contain
882 // references into the current collection set. This is used to
883 // update the remembered sets of the regions in the collection
884 // set in the event of an evacuation failure.
885 DirtyCardQueueSet _into_cset_dirty_card_queue_set;
886
887 // After a collection pause, make the regions in the CS into free
888 // regions.
889 void free_collection_set(HeapRegion* cs_head, EvacuationInfo& evacuation_info);
890
891 // Abandon the current collection set without recording policy
892 // statistics or updating free lists.
893 void abandon_collection_set(HeapRegion* cs_head);
894
895 // The concurrent marker (and the thread it runs in.)
896 ConcurrentMark* _cm;
897 ConcurrentMarkThread* _cmThread;
898
899 // The concurrent refiner.
1047 // _is_alive_non_header field. Supplying a value for the
1048 // _is_alive_non_header field is optional but doing so prevents
1049 // unnecessary additions to the discovered lists during reference
1050 // discovery.
1051 G1CMIsAliveClosure _is_alive_closure_cm;
1052
1053 // Cache used by G1CollectedHeap::start_cset_region_for_worker().
1054 HeapRegion** _worker_cset_start_region;
1055
1056 // Time stamp to validate the regions recorded in the cache
1057 // used by G1CollectedHeap::start_cset_region_for_worker().
1058 // The heap region entry for a given worker is valid iff
1059 // the associated time stamp value matches the current value
1060 // of G1CollectedHeap::_gc_time_stamp.
1061 uint* _worker_cset_start_region_time_stamp;
1062
1063 volatile bool _free_regions_coming;
1064
1065 public:
1066
1067 bool refine_cte_cl_concurrency();
1068 void set_refine_cte_cl_concurrency(bool concurrent);
1069
1070 RefToScanQueue *task_queue(uint i) const;
1071
1072 uint num_task_queues() const;
1073
1074 // A set of cards where updates happened during the GC
1075 DirtyCardQueueSet& dirty_card_queue_set() { return _dirty_card_queue_set; }
1076
1077 // A DirtyCardQueueSet that is used to hold cards that contain
1078 // references into the current collection set. This is used to
1079 // update the remembered sets of the regions in the collection
1080 // set in the event of an evacuation failure.
1081 DirtyCardQueueSet& into_cset_dirty_card_queue_set()
1082 { return _into_cset_dirty_card_queue_set; }
1083
1084 // Create a G1CollectedHeap with the specified policy.
1085 // Must call the initialize method afterwards.
1086 // May not return if something goes wrong.
1087 G1CollectedHeap(G1CollectorPolicy* policy);
|