< prev index next >

src/hotspot/share/gc/parallel/psPromotionManager.cpp

Print this page

275 
276 template <class T> void PSPromotionManager::process_array_chunk_work(
277                                                  oop obj,
278                                                  int start, int end) {
279   assert(start <= end, "invariant");
280   T* const base      = (T*)objArrayOop(obj)->base();
281   T* p               = base + start;
282   T* const chunk_end = base + end;
283   while (p < chunk_end) {
284     if (PSScavenge::should_scavenge(p)) {
285       claim_or_forward_depth(p);
286     }
287     ++p;
288   }
289 }
290 
291 void PSPromotionManager::process_array_chunk(PartialArrayScanTask task) {
292   assert(PSChunkLargeArrays, "invariant");
293 
294   oop old = task.to_source_array();
295   assert(old->is_objArray(), "invariant");
296   assert(old->is_forwarded(), "invariant");
297 
298   TASKQUEUE_STATS_ONLY(++_array_chunks_processed);
299 
300   oop const obj = old->forwardee();
301 
302   int start;
303   int const end = arrayOop(old)->length();
304   if (end > (int) _min_array_size_for_chunking) {
305     // we'll chunk more
306     start = end - _array_chunk_size;
307     assert(start > 0, "invariant");
308     arrayOop(old)->set_length(start);
309     push_depth(ScannerTask(PartialArrayScanTask(old)));
310     TASKQUEUE_STATS_ONLY(++_array_chunk_pushes);
311   } else {
312     // this is the final chunk for this array
313     start = 0;
314     int const actual_length = arrayOop(obj)->length();
315     arrayOop(old)->set_length(actual_length);
316   }
317 
318   if (UseCompressedOops) {
319     process_array_chunk_work<narrowOop>(obj, start, end);
320   } else {
321     process_array_chunk_work<oop>(obj, start, end);
322   }
323 }
324 
325 oop PSPromotionManager::oop_promotion_failed(oop obj, markWord obj_mark) {
326   assert(_old_gen_is_full || PromotionFailureALot, "Sanity");
327 
328   // Attempt to CAS in the header.
329   // This tests if the header is still the same as when
330   // this started.  If it is the same (i.e., no forwarding
331   // pointer has been installed), then this thread owns
332   // it.
333   if (obj->forward_to_atomic(obj, obj_mark) == NULL) {
334     // We won any races, we "own" this object.
335     assert(obj == obj->forwardee(), "Sanity");
336 
337     _promotion_failed_info.register_copy_failure(obj->size());
338 
339     push_contents(obj);
340 
341     // Save the markWord of promotion-failed objs in _preserved_marks for later
342     // restoration. This way we don't have to walk the young-gen to locate
343     // these promotion-failed objs.
344     _preserved_marks->push_always(obj, obj_mark);
345   }  else {
346     // We lost, someone else "owns" this object
347     guarantee(obj->is_forwarded(), "Object must be forwarded if the cas failed.");
348 
349     // No unallocation to worry about.
350     obj = obj->forwardee();
351   }
352 
353   return obj;

275 
276 template <class T> void PSPromotionManager::process_array_chunk_work(
277                                                  oop obj,
278                                                  int start, int end) {
279   assert(start <= end, "invariant");
280   T* const base      = (T*)objArrayOop(obj)->base();
281   T* p               = base + start;
282   T* const chunk_end = base + end;
283   while (p < chunk_end) {
284     if (PSScavenge::should_scavenge(p)) {
285       claim_or_forward_depth(p);
286     }
287     ++p;
288   }
289 }
290 
291 void PSPromotionManager::process_array_chunk(PartialArrayScanTask task) {
292   assert(PSChunkLargeArrays, "invariant");
293 
294   oop old = task.to_source_array();

295   assert(old->is_forwarded(), "invariant");
296 
297   TASKQUEUE_STATS_ONLY(++_array_chunks_processed);
298 
299   oop const obj = old->forwardee();
300 
301   int start;
302   int const end = arrayOop(old)->length();
303   if (end > (int) _min_array_size_for_chunking) {
304     // we'll chunk more
305     start = end - _array_chunk_size;
306     assert(start > 0, "invariant");
307     arrayOop(old)->set_length(start);
308     push_depth(ScannerTask(PartialArrayScanTask(old)));
309     TASKQUEUE_STATS_ONLY(++_array_chunk_pushes);
310   } else {
311     // this is the final chunk for this array
312     start = 0;
313     int const actual_length = arrayOop(obj)->length();
314     arrayOop(old)->set_length(actual_length);
315   }
316 
317   if (UseCompressedOops) {
318     process_array_chunk_work<narrowOop>(obj, start, end);
319   } else {
320     process_array_chunk_work<oop>(obj, start, end);
321   }
322 }
323 
324 oop PSPromotionManager::oop_promotion_failed(oop obj, markWord obj_mark) {
325   assert(_old_gen_is_full || PromotionFailureALot, "Sanity");
326 
327   // Attempt to CAS in the header.
328   // This tests if the header is still the same as when
329   // this started.  If it is the same (i.e., no forwarding
330   // pointer has been installed), then this thread owns
331   // it.
332   if (obj->forward_to_self_atomic(obj_mark) == NULL) {
333     // We won any races, we "own" this object.
334     assert(obj == obj->forwardee(), "Sanity");
335 
336     _promotion_failed_info.register_copy_failure(obj->size());
337 
338     push_contents(obj);
339 
340     // Save the markWord of promotion-failed objs in _preserved_marks for later
341     // restoration. This way we don't have to walk the young-gen to locate
342     // these promotion-failed objs.
343     _preserved_marks->push_always(obj, obj_mark);
344   }  else {
345     // We lost, someone else "owns" this object
346     guarantee(obj->is_forwarded(), "Object must be forwarded if the cas failed.");
347 
348     // No unallocation to worry about.
349     obj = obj->forwardee();
350   }
351 
352   return obj;
< prev index next >