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