@@ -287,6 +287,8 @@ class G1PrepareEvacuationTask : public WorkerTask {
287287 class G1PrepareRegionsClosure : public G1HeapRegionClosure {
288288 G1CollectedHeap* _g1h;
289289 G1PrepareEvacuationTask* _parent_task;
290+ G1EvacFailureRegions* _evac_failure_regions;
291+ uint _worker_id;
290292 uint _worker_humongous_total;
291293 uint _worker_humongous_candidates;
292294
@@ -361,9 +363,14 @@ class G1PrepareEvacuationTask : public WorkerTask {
361363 }
362364
363365 public:
364- G1PrepareRegionsClosure (G1CollectedHeap* g1h, G1PrepareEvacuationTask* parent_task) :
366+ G1PrepareRegionsClosure (G1CollectedHeap* g1h,
367+ G1PrepareEvacuationTask* parent_task,
368+ G1EvacFailureRegions* evac_failure_regions,
369+ uint worker_id) :
365370 _g1h (g1h),
366371 _parent_task (parent_task),
372+ _evac_failure_regions (evac_failure_regions),
373+ _worker_id (worker_id),
367374 _worker_humongous_total (0 ),
368375 _worker_humongous_candidates (0 ) { }
369376
@@ -373,6 +380,13 @@ class G1PrepareEvacuationTask : public WorkerTask {
373380 }
374381
375382 virtual bool do_heap_region (G1HeapRegion* hr) {
383+ // All pinned regions in the collection set must be registered as failed
384+ // regions here as there is no guarantee that there is a reference
385+ // reachable by Java code (i.e. only by native code).
386+ if (hr->in_collection_set () && hr->has_pinned_objects ()) {
387+ _evac_failure_regions->record (_worker_id, hr->hrm_index (), true /* cause_pinned */ );
388+ }
389+
376390 // First prepare the region for scanning
377391 _g1h->rem_set ()->prepare_region_for_scan (hr);
378392
@@ -415,22 +429,25 @@ class G1PrepareEvacuationTask : public WorkerTask {
415429 };
416430
417431 G1CollectedHeap* _g1h;
432+ G1EvacFailureRegions* _evac_failure_regions;
418433 G1HeapRegionClaimer _claimer;
419434 volatile uint _humongous_total;
420435 volatile uint _humongous_candidates;
421436
422437 G1MonotonicArenaMemoryStats _all_card_set_stats;
423438
424439public:
425- G1PrepareEvacuationTask (G1CollectedHeap* g1h) :
440+ G1PrepareEvacuationTask (G1CollectedHeap* g1h, G1EvacFailureRegions* evac_failure_regions ) :
426441 WorkerTask (" Prepare Evacuation" ),
427442 _g1h (g1h),
443+ _evac_failure_regions (evac_failure_regions),
428444 _claimer (_g1h->workers ()->active_workers()),
429445 _humongous_total(0 ),
430- _humongous_candidates(0 ) { }
446+ _humongous_candidates(0 ),
447+ _all_card_set_stats() { }
431448
432449 void work (uint worker_id) {
433- G1PrepareRegionsClosure cl (_g1h, this );
450+ G1PrepareRegionsClosure cl (_g1h, this , _evac_failure_regions, worker_id );
434451 _g1h->heap_region_par_iterate_from_worker_offset (&cl, &_claimer, worker_id);
435452
436453 MutexLocker x (G1RareEvent_lock, Mutex::_no_safepoint_check_flag);
@@ -472,7 +489,8 @@ void G1YoungCollector::set_young_collection_default_active_worker_threads(){
472489 log_info (gc,task)(" Using %u workers of %u for evacuation" , active_workers, workers ()->max_workers ());
473490}
474491
475- void G1YoungCollector::pre_evacuate_collection_set (G1EvacInfo* evacuation_info) {
492+ void G1YoungCollector::pre_evacuate_collection_set (G1EvacInfo* evacuation_info,
493+ G1EvacFailureRegions* evac_failure_regions) {
476494 // Flush various data in thread-local buffers to be able to determine the collection
477495 // set
478496 {
@@ -511,7 +529,7 @@ void G1YoungCollector::pre_evacuate_collection_set(G1EvacInfo* evacuation_info)
511529 }
512530
513531 {
514- G1PrepareEvacuationTask g1_prep_task (_g1h);
532+ G1PrepareEvacuationTask g1_prep_task (_g1h, evac_failure_regions );
515533 Tickspan task_time = run_task_timed (&g1_prep_task);
516534
517535 G1MonotonicArenaMemoryStats sampled_card_set_stats = g1_prep_task.all_card_set_stats ();
@@ -1104,7 +1122,7 @@ void G1YoungCollector::collect() {
11041122 // other trivial setup above).
11051123 policy ()->record_young_collection_start ();
11061124
1107- pre_evacuate_collection_set (jtm.evacuation_info ());
1125+ pre_evacuate_collection_set (jtm.evacuation_info (), &_evac_failure_regions );
11081126
11091127 G1ParScanThreadStateSet per_thread_states (_g1h,
11101128 workers ()->active_workers (),
0 commit comments