1 /*
2 * Copyright (c) 2014, 2019, 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_G1PARSCANTHREADSTATE_HPP
26 #define SHARE_GC_G1_G1PARSCANTHREADSTATE_HPP
27
28 #include "gc/g1/g1CardTable.hpp"
29 #include "gc/g1/g1CollectedHeap.hpp"
30 #include "gc/g1/g1RedirtyCardsQueue.hpp"
31 #include "gc/g1/g1OopClosures.hpp"
32 #include "gc/g1/g1Policy.hpp"
33 #include "gc/g1/g1RemSet.hpp"
34 #include "gc/g1/heapRegionRemSet.hpp"
35 #include "gc/shared/ageTable.hpp"
36 #include "memory/allocation.hpp"
37 #include "oops/oop.hpp"
38 #include "utilities/ticks.hpp"
39
40 class G1OopStarChunkedList;
41 class G1PLABAllocator;
42 class G1EvacuationRootClosures;
43 class HeapRegion;
44 class outputStream;
45
46 class G1ParScanThreadState : public CHeapObj<mtGC> {
47 G1CollectedHeap* _g1h;
48 RefToScanQueue* _refs;
49 G1RedirtyCardsQueue _rdcq;
50 G1CardTable* _ct;
51 G1EvacuationRootClosures* _closures;
52
53 G1PLABAllocator* _plab_allocator;
54
55 AgeTable _age_table;
56 G1HeapRegionAttr _dest[G1HeapRegionAttr::Num];
57 // Local tenuring threshold.
58 uint _tenuring_threshold;
59 G1ScanEvacuatedObjClosure _scanner;
60
61 uint _worker_id;
62
63 // Remember the last enqueued card to avoid enqueuing the same card over and over;
64 // since we only ever scan a card once, this is sufficient.
65 size_t _last_enqueued_card;
66
67 // Upper and lower threshold to start and end work queue draining.
68 uint const _stack_trim_upper_threshold;
97 G1OopStarChunkedList* _oops_into_optional_regions;
98
99 G1NUMA* _numa;
100
101 // Records how many object allocations happened at each node during copy to survivor.
102 // Only starts recording when log of gc+heap+numa is enabled and its data is
103 // transferred when flushed.
104 size_t* _obj_alloc_stat;
105
106 public:
107 G1ParScanThreadState(G1CollectedHeap* g1h,
108 G1RedirtyCardsQueueSet* rdcqs,
109 uint worker_id,
110 size_t young_cset_length,
111 size_t optional_cset_length);
112 virtual ~G1ParScanThreadState();
113
114 void set_ref_discoverer(ReferenceDiscoverer* rd) { _scanner.set_ref_discoverer(rd); }
115
116 #ifdef ASSERT
117 bool queue_is_empty() const { return _refs->is_empty(); }
118
119 bool verify_ref(narrowOop* ref) const;
120 bool verify_ref(oop* ref) const;
121 bool verify_task(StarTask ref) const;
122 #endif // ASSERT
123
124 template <class T> void do_oop_ext(T* ref);
125 template <class T> void push_on_queue(T* ref);
126
127 template <class T> void enqueue_card_if_tracked(G1HeapRegionAttr region_attr, T* p, oop o) {
128 assert(!HeapRegion::is_in_same_region(p, o), "Should have filtered out cross-region references already.");
129 assert(!_g1h->heap_region_containing(p)->is_young(), "Should have filtered out from-young references already.");
130
131 #ifdef ASSERT
132 HeapRegion* const hr_obj = _g1h->heap_region_containing(o);
133 assert(region_attr.needs_remset_update() == hr_obj->rem_set()->is_tracked(),
134 "State flag indicating remset tracking disagrees (%s) with actual remembered set (%s) for region %u",
135 BOOL_TO_STR(region_attr.needs_remset_update()),
136 BOOL_TO_STR(hr_obj->rem_set()->is_tracked()),
137 hr_obj->hrm_index());
138 #endif
139 if (!region_attr.needs_remset_update()) {
140 return;
141 }
142 size_t card_index = ct()->index_for(p);
143 // If the card hasn't been added to the buffer, do it.
144 if (_last_enqueued_card != card_index) {
145 redirty_cards_queue().enqueue(ct()->byte_for_index(card_index));
146 _last_enqueued_card = card_index;
147 }
148 }
149
150 G1EvacuationRootClosures* closures() { return _closures; }
151 uint worker_id() { return _worker_id; }
152
153 size_t lab_waste_words() const;
154 size_t lab_undo_waste_words() const;
155
156 // Pass locally gathered statistics to global state. Returns the total number of
157 // HeapWords copied.
158 size_t flush(size_t* surviving_young_words);
159
160 private:
161 #define G1_PARTIAL_ARRAY_MASK 0x2
162
163 inline bool has_partial_array_mask(oop* ref) const {
164 return ((uintptr_t)ref & G1_PARTIAL_ARRAY_MASK) == G1_PARTIAL_ARRAY_MASK;
165 }
166
167 // We never encode partial array oops as narrowOop*, so return false immediately.
168 // This allows the compiler to create optimized code when popping references from
169 // the work queue.
170 inline bool has_partial_array_mask(narrowOop* ref) const {
171 assert(((uintptr_t)ref & G1_PARTIAL_ARRAY_MASK) != G1_PARTIAL_ARRAY_MASK, "Partial array oop reference encoded as narrowOop*");
172 return false;
173 }
174
175 // Only implement set_partial_array_mask() for regular oops, not for narrowOops.
176 // We always encode partial arrays as regular oop, to allow the
177 // specialization for has_partial_array_mask() for narrowOops above.
178 // This means that unintentional use of this method with narrowOops are caught
179 // by the compiler.
180 inline oop* set_partial_array_mask(oop obj) const {
181 assert(((uintptr_t)(void *)obj & G1_PARTIAL_ARRAY_MASK) == 0, "Information loss!");
182 return (oop*) ((uintptr_t)(void *)obj | G1_PARTIAL_ARRAY_MASK);
183 }
184
185 inline oop clear_partial_array_mask(oop* ref) const {
186 return cast_to_oop((intptr_t)ref & ~G1_PARTIAL_ARRAY_MASK);
187 }
188
189 inline void do_oop_partial_array(oop* p);
190
191 // This method is applied to the fields of the objects that have just been copied.
192 template <class T> inline void do_oop_evac(T* p);
193
194 inline void deal_with_reference(oop* ref_to_scan);
195 inline void deal_with_reference(narrowOop* ref_to_scan);
196
197 inline void dispatch_reference(StarTask ref);
198
199 // Tries to allocate word_sz in the PLAB of the next "generation" after trying to
200 // allocate into dest. Previous_plab_refill_failed indicates whether previous
201 // PLAB refill for the original (source) object failed.
202 // Returns a non-NULL pointer if successful, and updates dest if required.
203 // Also determines whether we should continue to try to allocate into the various
204 // generations or just end trying to allocate.
205 HeapWord* allocate_in_next_plab(G1HeapRegionAttr* dest,
206 size_t word_sz,
207 bool previous_plab_refill_failed,
208 uint node_index);
209
210 inline G1HeapRegionAttr next_region_attr(G1HeapRegionAttr const region_attr, markWord const m, uint& age);
211
212 void report_promotion_event(G1HeapRegionAttr const dest_attr,
213 oop const old, size_t word_sz, uint age,
214 HeapWord * const obj_ptr, uint node_index) const;
215
216 inline bool needs_partial_trimming() const;
217 inline bool is_partially_trimmed() const;
218
219 inline void trim_queue_to_threshold(uint threshold);
220
221 // NUMA statistics related methods.
222 inline void initialize_numa_stats();
223 inline void flush_numa_stats();
224 inline void update_numa_stats(uint node_index);
225
226 public:
227 oop copy_to_survivor_space(G1HeapRegionAttr const region_attr, oop const obj, markWord const old_mark);
228
229 void trim_queue();
230 void trim_queue_partially();
231
232 Tickspan trim_ticks() const;
233 void reset_trim_ticks();
234
235 inline void steal_and_trim_queue(RefToScanQueueSet *task_queues);
236
237 // An attempt to evacuate "obj" has failed; take necessary steps.
238 oop handle_evacuation_failure_par(oop obj, markWord m);
239
240 template <typename T>
241 inline void remember_root_into_optional_region(T* p);
242 template <typename T>
243 inline void remember_reference_into_optional_region(T* p);
244
245 inline G1OopStarChunkedList* oops_into_optional_region(const HeapRegion* hr);
246 };
247
248 class G1ParScanThreadStateSet : public StackObj {
249 G1CollectedHeap* _g1h;
250 G1RedirtyCardsQueueSet* _rdcqs;
251 G1ParScanThreadState** _states;
252 size_t* _surviving_young_words_total;
253 size_t _young_cset_length;
254 size_t _optional_cset_length;
255 uint _n_workers;
|
1 /*
2 * Copyright (c) 2014, 2020, 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_G1PARSCANTHREADSTATE_HPP
26 #define SHARE_GC_G1_G1PARSCANTHREADSTATE_HPP
27
28 #include "gc/g1/g1CardTable.hpp"
29 #include "gc/g1/g1CollectedHeap.hpp"
30 #include "gc/g1/g1RedirtyCardsQueue.hpp"
31 #include "gc/g1/g1OopClosures.hpp"
32 #include "gc/g1/g1Policy.hpp"
33 #include "gc/g1/g1RemSet.hpp"
34 #include "gc/g1/heapRegionRemSet.hpp"
35 #include "gc/shared/ageTable.hpp"
36 #include "gc/shared/taskqueue.hpp"
37 #include "memory/allocation.hpp"
38 #include "oops/oop.hpp"
39 #include "utilities/ticks.hpp"
40
41 class G1OopStarChunkedList;
42 class G1PLABAllocator;
43 class G1EvacuationRootClosures;
44 class HeapRegion;
45 class outputStream;
46
47 class G1ParScanThreadState : public CHeapObj<mtGC> {
48 G1CollectedHeap* _g1h;
49 ScannerTasksQueue* _task_queue;
50 G1RedirtyCardsQueue _rdcq;
51 G1CardTable* _ct;
52 G1EvacuationRootClosures* _closures;
53
54 G1PLABAllocator* _plab_allocator;
55
56 AgeTable _age_table;
57 G1HeapRegionAttr _dest[G1HeapRegionAttr::Num];
58 // Local tenuring threshold.
59 uint _tenuring_threshold;
60 G1ScanEvacuatedObjClosure _scanner;
61
62 uint _worker_id;
63
64 // Remember the last enqueued card to avoid enqueuing the same card over and over;
65 // since we only ever scan a card once, this is sufficient.
66 size_t _last_enqueued_card;
67
68 // Upper and lower threshold to start and end work queue draining.
69 uint const _stack_trim_upper_threshold;
98 G1OopStarChunkedList* _oops_into_optional_regions;
99
100 G1NUMA* _numa;
101
102 // Records how many object allocations happened at each node during copy to survivor.
103 // Only starts recording when log of gc+heap+numa is enabled and its data is
104 // transferred when flushed.
105 size_t* _obj_alloc_stat;
106
107 public:
108 G1ParScanThreadState(G1CollectedHeap* g1h,
109 G1RedirtyCardsQueueSet* rdcqs,
110 uint worker_id,
111 size_t young_cset_length,
112 size_t optional_cset_length);
113 virtual ~G1ParScanThreadState();
114
115 void set_ref_discoverer(ReferenceDiscoverer* rd) { _scanner.set_ref_discoverer(rd); }
116
117 #ifdef ASSERT
118 bool queue_is_empty() const { return _task_queue->is_empty(); }
119 #endif
120
121 void verify_task(narrowOop* task) const NOT_DEBUG_RETURN;
122 void verify_task(oop* task) const NOT_DEBUG_RETURN;
123 void verify_task(PartialArrayScanTask task) const NOT_DEBUG_RETURN;
124 void verify_task(ScannerTask task) const NOT_DEBUG_RETURN;
125
126 void push_on_queue(ScannerTask task);
127
128 template <class T> void enqueue_card_if_tracked(G1HeapRegionAttr region_attr, T* p, oop o) {
129 assert(!HeapRegion::is_in_same_region(p, o), "Should have filtered out cross-region references already.");
130 assert(!_g1h->heap_region_containing(p)->is_young(), "Should have filtered out from-young references already.");
131
132 #ifdef ASSERT
133 HeapRegion* const hr_obj = _g1h->heap_region_containing(o);
134 assert(region_attr.needs_remset_update() == hr_obj->rem_set()->is_tracked(),
135 "State flag indicating remset tracking disagrees (%s) with actual remembered set (%s) for region %u",
136 BOOL_TO_STR(region_attr.needs_remset_update()),
137 BOOL_TO_STR(hr_obj->rem_set()->is_tracked()),
138 hr_obj->hrm_index());
139 #endif
140 if (!region_attr.needs_remset_update()) {
141 return;
142 }
143 size_t card_index = ct()->index_for(p);
144 // If the card hasn't been added to the buffer, do it.
145 if (_last_enqueued_card != card_index) {
146 redirty_cards_queue().enqueue(ct()->byte_for_index(card_index));
147 _last_enqueued_card = card_index;
148 }
149 }
150
151 G1EvacuationRootClosures* closures() { return _closures; }
152 uint worker_id() { return _worker_id; }
153
154 size_t lab_waste_words() const;
155 size_t lab_undo_waste_words() const;
156
157 // Pass locally gathered statistics to global state. Returns the total number of
158 // HeapWords copied.
159 size_t flush(size_t* surviving_young_words);
160
161 private:
162 inline void do_partial_array(PartialArrayScanTask task);
163
164 // This method is applied to the fields of the objects that have just been copied.
165 template <class T> inline void do_oop_evac(T* p);
166
167 inline void dispatch_task(ScannerTask task);
168
169 // Tries to allocate word_sz in the PLAB of the next "generation" after trying to
170 // allocate into dest. Previous_plab_refill_failed indicates whether previous
171 // PLAB refill for the original (source) object failed.
172 // Returns a non-NULL pointer if successful, and updates dest if required.
173 // Also determines whether we should continue to try to allocate into the various
174 // generations or just end trying to allocate.
175 HeapWord* allocate_in_next_plab(G1HeapRegionAttr* dest,
176 size_t word_sz,
177 bool previous_plab_refill_failed,
178 uint node_index);
179
180 inline G1HeapRegionAttr next_region_attr(G1HeapRegionAttr const region_attr, markWord const m, uint& age);
181
182 void report_promotion_event(G1HeapRegionAttr const dest_attr,
183 oop const old, size_t word_sz, uint age,
184 HeapWord * const obj_ptr, uint node_index) const;
185
186 inline bool needs_partial_trimming() const;
187 inline bool is_partially_trimmed() const;
188
189 inline void trim_queue_to_threshold(uint threshold);
190
191 // NUMA statistics related methods.
192 inline void initialize_numa_stats();
193 inline void flush_numa_stats();
194 inline void update_numa_stats(uint node_index);
195
196 public:
197 oop copy_to_survivor_space(G1HeapRegionAttr const region_attr, oop const obj, markWord const old_mark);
198
199 void trim_queue();
200 void trim_queue_partially();
201
202 Tickspan trim_ticks() const;
203 void reset_trim_ticks();
204
205 inline void steal_and_trim_queue(ScannerTasksQueueSet *task_queues);
206
207 // An attempt to evacuate "obj" has failed; take necessary steps.
208 oop handle_evacuation_failure_par(oop obj, markWord m);
209
210 template <typename T>
211 inline void remember_root_into_optional_region(T* p);
212 template <typename T>
213 inline void remember_reference_into_optional_region(T* p);
214
215 inline G1OopStarChunkedList* oops_into_optional_region(const HeapRegion* hr);
216 };
217
218 class G1ParScanThreadStateSet : public StackObj {
219 G1CollectedHeap* _g1h;
220 G1RedirtyCardsQueueSet* _rdcqs;
221 G1ParScanThreadState** _states;
222 size_t* _surviving_young_words_total;
223 size_t _young_cset_length;
224 size_t _optional_cset_length;
225 uint _n_workers;
|