< prev index next >

src/hotspot/share/gc/shenandoah/shenandoahMark.inline.hpp

Print this page

 56   shenandoah_assert_not_in_cset_except(nullptr, obj, ShenandoahHeap::heap()->cancelled_gc());
 57 
 58   Klass* klass = obj->klass();
 59 
 60   // Are we in weak subgraph scan?
 61   bool weak = task->is_weak();
 62   cl->set_weak(weak);
 63 
 64   if (task->is_not_chunked()) {
 65     // Dispatch based on object type. The case order does not seem to affect performance,
 66     // so it matches the enum order for consistency.
 67     switch (klass->kind()) {
 68       case Klass::InstanceKlassKind: {
 69         // Regular instance.
 70         if (STRING_DEDUP && (klass == vmClasses::String_klass())) {
 71           dedup_string(obj, req);
 72         }
 73         InstanceKlass::cast(klass)->oop_oop_iterate<OT>(obj, cl);
 74         break;
 75       }





 76       case Klass::InstanceRefKlassKind: {
 77         // (Weak) reference instance.
 78         InstanceRefKlass::cast(klass)->oop_oop_iterate<OT>(obj, cl);
 79         break;
 80       }
 81       case Klass::InstanceMirrorKlassKind:
 82       case Klass::InstanceClassLoaderKlassKind: {
 83         // Remaining rare classes, dispatch generically.
 84         obj->oop_iterate(cl);
 85         break;
 86       }
 87       case Klass::InstanceStackChunkKlassKind: {
 88         // Stack chunk. Loom doesn't support mixing of weak marking and strong marking
 89         // of stack chunks, upgrade to strong right away.
 90         cl->set_weak(false);
 91         InstanceStackChunkKlass::cast(klass)->oop_oop_iterate<OT>(obj, cl);
 92         break;
 93       }
 94       case Klass::TypeArrayKlassKind: {
 95         // Primitive array. Do nothing, no oops there. We use the same
 96         // performance tweak TypeArrayKlass::oop_oop_iterate_impl is using:
 97         // We skip iterating over the klass pointer since we know that
 98         // Universe::TypeArrayKlass never moves.
 99         break;
100       }
101       case Klass::ObjArrayKlassKind: {
102         // Object array and no chunk is set. Must be the first



103         // time we visit it, start the chunked processing.
104         do_chunked_array_start<T, OT>(q, cl, obj, klass, weak);
105         break;
106       }





107       default: {
108         fatal("Unknown klass kind: %d", klass->kind());
109       }
110     }
111     // Count liveness the last: push the outstanding work to the queues first
112     // Avoid double-counting objects that are visited twice due to upgrade
113     // from final- to strong mark.
114     if (task->count_liveness()) {
115       count_liveness<GENERATION>(live_data, obj, klass, worker_id);
116     }
117   } else {
118     // Object array chunk. Process it.
119     do_chunked_array<T, OT>(q, cl, obj, klass, task->chunk(), task->pow(), weak);
120   }
121 }
122 
123 inline void ShenandoahMark::dedup_string(oop obj, StringDedup::Requests* const req) {
124   assert(req != nullptr, "Should be available if dedup is enabled");
125 
126   // Skip if already requested or dedup is forbidden.
127   // The overwhelming majority of Strings would be filtered here.
128   // These bits are also sticky, so older Strings would be filtered here too.
129   if (java_lang_String::deduplication_requested_or_forbidden(obj)) {
130     return;
131   }
132 
133   // Accept deduplication request.
134   if (!java_lang_String::test_and_set_deduplication_requested(obj)) {
135     req->add(obj);
136   }
137 }
138 

165     } else {
166       // still good, remember in locals
167       live_data[region_idx] = (ShenandoahLiveData) new_val;
168     }
169   } else {
170     shenandoah_assert_in_correct_region(nullptr, obj);
171     size_t num_regions = ShenandoahHeapRegion::required_regions(size * HeapWordSize);
172 
173     assert(region->is_affiliated(), "Do not count live data within FREE Humongous Start Region %zu", region_idx);
174     for (size_t i = region_idx; i < region_idx + num_regions; i++) {
175       ShenandoahHeapRegion* chain_reg = heap->get_region(i);
176       assert(chain_reg->is_humongous(), "Expecting a humongous region");
177       assert(chain_reg->is_affiliated(), "Do not count live data within FREE Humongous Continuation Region %zu", i);
178       chain_reg->increase_live_data_gc_words(chain_reg->used() >> LogHeapWordSize);
179     }
180   }
181 }
182 
183 template <class T, class OT>
184 void ShenandoahMark::do_chunked_array_start(ShenandoahObjToScanQueue* q, T* cl, oop obj, Klass* klass, bool weak) {
185   assert(obj->is_objArray(), "expect object array");
186   objArrayOop array = objArrayOop(obj);
187   int len = array->length();
188 
189   // Mark objArray klass metadata
190   if (Devirtualizer::do_metadata(cl)) {
191     Devirtualizer::do_klass(cl, klass);
192   }
193 
194   if (len <= (int) ObjArrayMarkingStride*2) {
195     // A few slices only, process directly
196     ObjArrayKlass::cast(klass)->oop_oop_iterate_elements_range<OT>(array, cl, 0, len);
197   } else {
198     int bits = log2i_graceful(len);
199     // Compensate for non-power-of-two arrays, cover the array in excess:
200     if (len != (1 << bits)) bits++;
201 
202     // Only allow full chunks on the queue. This frees do_chunked_array() from checking from/to
203     // boundaries against array->length(), touching the array header on every chunk.
204     //
205     // To do this, we cut the prefix in full-sized chunks, and submit them on the queue.
206     // If the array is not divided in chunk sizes, then there would be an irregular tail,
207     // which we will process separately.
208 
209     int last_idx = 0;
210 
211     int chunk = 1;
212     int pow = bits;
213 
214     // Handle overflow
215     if (pow >= 31) {
216       assert (pow == 31, "sanity");

225     // successful right boundary to figure out the irregular tail.
226     while ((1 << pow) > (int)ObjArrayMarkingStride &&
227            (chunk*2 < ShenandoahMarkTask::chunk_size())) {
228       pow--;
229       int left_chunk = chunk*2 - 1;
230       int right_chunk = chunk*2;
231       int left_chunk_end = left_chunk * (1 << pow);
232       if (left_chunk_end < len) {
233         bool pushed = q->push(ShenandoahMarkTask(array, true, weak, left_chunk, pow));
234         assert(pushed, "overflow queue should always succeed pushing");
235         chunk = right_chunk;
236         last_idx = left_chunk_end;
237       } else {
238         chunk = left_chunk;
239       }
240     }
241 
242     // Process the irregular tail, if present
243     int from = last_idx;
244     if (from < len) {
245       ObjArrayKlass::cast(klass)->oop_oop_iterate_elements_range<OT>(array, cl, from, len);
246     }
247   }
248 }
249 
250 template <class T, class OT>
251 void ShenandoahMark::do_chunked_array(ShenandoahObjToScanQueue* q, T* cl, oop obj, Klass* klass, int chunk, int pow, bool weak) {
252   assert(obj->is_objArray(), "expect object array");
253   objArrayOop array = objArrayOop(obj);
254 
255   // Split out tasks, as suggested in ShenandoahMarkTask docs. Avoid pushing tasks that
256   // are known to start beyond the array.
257   while ((1 << pow) > (int)ObjArrayMarkingStride && (chunk*2 < ShenandoahMarkTask::chunk_size())) {
258     pow--;
259     chunk *= 2;
260     bool pushed = q->push(ShenandoahMarkTask(array, true, weak, chunk - 1, pow));
261     assert(pushed, "overflow queue should always succeed pushing");
262   }
263 
264   int chunk_size = 1 << pow;
265 
266   int from = (chunk - 1) * chunk_size;
267   int to = chunk * chunk_size;
268 
269 #ifdef ASSERT
270   int len = array->length();
271   assert (0 <= from && from < len, "from is sane: %d/%d", from, len);
272   assert (0 < to && to <= len, "to is sane: %d/%d", to, len);
273 #endif
274 
275   ObjArrayKlass::cast(klass)->oop_oop_iterate_elements_range<OT>(array, cl, from, to);
276 }
277 
278 template <ShenandoahGenerationType GENERATION>
279 class ShenandoahSATBBufferClosure : public SATBBufferClosure {
280 private:
281   ShenandoahObjToScanQueue* _queue;
282   ShenandoahObjToScanQueue* _old_queue;
283   ShenandoahHeap* _heap;
284   ShenandoahMarkingContext* const _mark_context;
285 public:
286   ShenandoahSATBBufferClosure(ShenandoahObjToScanQueue* q, ShenandoahObjToScanQueue* old_q) :
287     _queue(q),
288     _old_queue(old_q),
289     _heap(ShenandoahHeap::heap()),
290     _mark_context(_heap->marking_context())
291   {
292   }
293 
294   void do_buffer(void **buffer, size_t size) {
295     assert(size == 0 || !_heap->has_forwarded_objects() || _heap->is_concurrent_old_mark_in_progress(), "Forwarded objects are not expected here");

 56   shenandoah_assert_not_in_cset_except(nullptr, obj, ShenandoahHeap::heap()->cancelled_gc());
 57 
 58   Klass* klass = obj->klass();
 59 
 60   // Are we in weak subgraph scan?
 61   bool weak = task->is_weak();
 62   cl->set_weak(weak);
 63 
 64   if (task->is_not_chunked()) {
 65     // Dispatch based on object type. The case order does not seem to affect performance,
 66     // so it matches the enum order for consistency.
 67     switch (klass->kind()) {
 68       case Klass::InstanceKlassKind: {
 69         // Regular instance.
 70         if (STRING_DEDUP && (klass == vmClasses::String_klass())) {
 71           dedup_string(obj, req);
 72         }
 73         InstanceKlass::cast(klass)->oop_oop_iterate<OT>(obj, cl);
 74         break;
 75       }
 76       case Klass::InlineKlassKind: {
 77         // Inline instance.
 78         InlineKlass::cast(klass)->oop_oop_iterate<OT>(obj, cl);
 79         break;
 80       }
 81       case Klass::InstanceRefKlassKind: {
 82         // (Weak) reference instance.
 83         InstanceRefKlass::cast(klass)->oop_oop_iterate<OT>(obj, cl);
 84         break;
 85       }
 86       case Klass::InstanceMirrorKlassKind:
 87       case Klass::InstanceClassLoaderKlassKind: {
 88         // Remaining rare classes, dispatch generically.
 89         obj->oop_iterate(cl);
 90         break;
 91       }
 92       case Klass::InstanceStackChunkKlassKind: {
 93         // Stack chunk. Loom doesn't support mixing of weak marking and strong marking
 94         // of stack chunks, upgrade to strong right away.
 95         cl->set_weak(false);
 96         InstanceStackChunkKlass::cast(klass)->oop_oop_iterate<OT>(obj, cl);
 97         break;
 98       }
 99       case Klass::TypeArrayKlassKind: {
100         // Primitive array. Do nothing, no oops there. We use the same
101         // performance tweak TypeArrayKlass::oop_oop_iterate_impl is using:
102         // We skip iterating over the klass pointer since we know that
103         // Universe::TypeArrayKlass never moves.
104         break;
105       }
106       case Klass::ObjArrayKlassKind: {
107         fatal("Unexpected unrefined object array klass");
108       }
109       case Klass::RefArrayKlassKind: {
110         // Reference array and no chunk is set. Must be the first
111         // time we visit it, start the chunked processing.
112         do_chunked_array_start<T, OT>(q, cl, obj, klass, weak);
113         break;
114       }
115       case Klass::FlatArrayKlassKind: {
116         // Flat array, all elements are embedded.
117         FlatArrayKlass::cast(klass)->oop_oop_iterate<OT>(obj, cl);
118         break;
119       }
120       default: {
121         fatal("Unknown klass kind: %d", klass->kind());
122       }
123     }
124     // Count liveness the last: push the outstanding work to the queues first
125     // Avoid double-counting objects that are visited twice due to upgrade
126     // from final- to strong mark.
127     if (task->count_liveness()) {
128       count_liveness<GENERATION>(live_data, obj, klass, worker_id);
129     }
130   } else {
131     // Reference array chunk. Process it.
132     do_chunked_array<T, OT>(q, cl, obj, klass, task->chunk(), task->pow(), weak);
133   }
134 }
135 
136 inline void ShenandoahMark::dedup_string(oop obj, StringDedup::Requests* const req) {
137   assert(req != nullptr, "Should be available if dedup is enabled");
138 
139   // Skip if already requested or dedup is forbidden.
140   // The overwhelming majority of Strings would be filtered here.
141   // These bits are also sticky, so older Strings would be filtered here too.
142   if (java_lang_String::deduplication_requested_or_forbidden(obj)) {
143     return;
144   }
145 
146   // Accept deduplication request.
147   if (!java_lang_String::test_and_set_deduplication_requested(obj)) {
148     req->add(obj);
149   }
150 }
151 

178     } else {
179       // still good, remember in locals
180       live_data[region_idx] = (ShenandoahLiveData) new_val;
181     }
182   } else {
183     shenandoah_assert_in_correct_region(nullptr, obj);
184     size_t num_regions = ShenandoahHeapRegion::required_regions(size * HeapWordSize);
185 
186     assert(region->is_affiliated(), "Do not count live data within FREE Humongous Start Region %zu", region_idx);
187     for (size_t i = region_idx; i < region_idx + num_regions; i++) {
188       ShenandoahHeapRegion* chain_reg = heap->get_region(i);
189       assert(chain_reg->is_humongous(), "Expecting a humongous region");
190       assert(chain_reg->is_affiliated(), "Do not count live data within FREE Humongous Continuation Region %zu", i);
191       chain_reg->increase_live_data_gc_words(chain_reg->used() >> LogHeapWordSize);
192     }
193   }
194 }
195 
196 template <class T, class OT>
197 void ShenandoahMark::do_chunked_array_start(ShenandoahObjToScanQueue* q, T* cl, oop obj, Klass* klass, bool weak) {
198   assert(obj->is_refArray(), "expect ref array");
199   refArrayOop array = refArrayOop(obj);
200   int len = array->length();
201 
202   // Mark reference array klass metadata
203   if (Devirtualizer::do_metadata(cl)) {
204     Devirtualizer::do_klass(cl, klass);
205   }
206 
207   if (len <= (int) ObjArrayMarkingStride*2) {
208     // A few slices only, process directly
209     RefArrayKlass::cast(klass)->oop_oop_iterate_elements_range<OT>(array, cl, 0, len);
210   } else {
211     int bits = log2i_graceful(len);
212     // Compensate for non-power-of-two arrays, cover the array in excess:
213     if (len != (1 << bits)) bits++;
214 
215     // Only allow full chunks on the queue. This frees do_chunked_array() from checking from/to
216     // boundaries against array->length(), touching the array header on every chunk.
217     //
218     // To do this, we cut the prefix in full-sized chunks, and submit them on the queue.
219     // If the array is not divided in chunk sizes, then there would be an irregular tail,
220     // which we will process separately.
221 
222     int last_idx = 0;
223 
224     int chunk = 1;
225     int pow = bits;
226 
227     // Handle overflow
228     if (pow >= 31) {
229       assert (pow == 31, "sanity");

238     // successful right boundary to figure out the irregular tail.
239     while ((1 << pow) > (int)ObjArrayMarkingStride &&
240            (chunk*2 < ShenandoahMarkTask::chunk_size())) {
241       pow--;
242       int left_chunk = chunk*2 - 1;
243       int right_chunk = chunk*2;
244       int left_chunk_end = left_chunk * (1 << pow);
245       if (left_chunk_end < len) {
246         bool pushed = q->push(ShenandoahMarkTask(array, true, weak, left_chunk, pow));
247         assert(pushed, "overflow queue should always succeed pushing");
248         chunk = right_chunk;
249         last_idx = left_chunk_end;
250       } else {
251         chunk = left_chunk;
252       }
253     }
254 
255     // Process the irregular tail, if present
256     int from = last_idx;
257     if (from < len) {
258       RefArrayKlass::cast(klass)->oop_oop_iterate_elements_range<OT>(array, cl, from, len);
259     }
260   }
261 }
262 
263 template <class T, class OT>
264 void ShenandoahMark::do_chunked_array(ShenandoahObjToScanQueue* q, T* cl, oop obj, Klass* klass, int chunk, int pow, bool weak) {
265   assert(obj->is_refArray(), "expect ref array");
266   refArrayOop array = refArrayOop(obj);
267 
268   // Split out tasks, as suggested in ShenandoahMarkTask docs. Avoid pushing tasks that
269   // are known to start beyond the array.
270   while ((1 << pow) > (int)ObjArrayMarkingStride && (chunk*2 < ShenandoahMarkTask::chunk_size())) {
271     pow--;
272     chunk *= 2;
273     bool pushed = q->push(ShenandoahMarkTask(array, true, weak, chunk - 1, pow));
274     assert(pushed, "overflow queue should always succeed pushing");
275   }
276 
277   int chunk_size = 1 << pow;
278 
279   int from = (chunk - 1) * chunk_size;
280   int to = chunk * chunk_size;
281 
282 #ifdef ASSERT
283   int len = array->length();
284   assert (0 <= from && from < len, "from is sane: %d/%d", from, len);
285   assert (0 < to && to <= len, "to is sane: %d/%d", to, len);
286 #endif
287 
288   RefArrayKlass::cast(klass)->oop_oop_iterate_elements_range<OT>(array, cl, from, to);
289 }
290 
291 template <ShenandoahGenerationType GENERATION>
292 class ShenandoahSATBBufferClosure : public SATBBufferClosure {
293 private:
294   ShenandoahObjToScanQueue* _queue;
295   ShenandoahObjToScanQueue* _old_queue;
296   ShenandoahHeap* _heap;
297   ShenandoahMarkingContext* const _mark_context;
298 public:
299   ShenandoahSATBBufferClosure(ShenandoahObjToScanQueue* q, ShenandoahObjToScanQueue* old_q) :
300     _queue(q),
301     _old_queue(old_q),
302     _heap(ShenandoahHeap::heap()),
303     _mark_context(_heap->marking_context())
304   {
305   }
306 
307   void do_buffer(void **buffer, size_t size) {
308     assert(size == 0 || !_heap->has_forwarded_objects() || _heap->is_concurrent_old_mark_in_progress(), "Forwarded objects are not expected here");
< prev index next >