32 #include "gc/g1/concurrentG1Refine.hpp" |
32 #include "gc/g1/concurrentG1Refine.hpp" |
33 #include "gc/g1/concurrentG1RefineThread.hpp" |
33 #include "gc/g1/concurrentG1RefineThread.hpp" |
34 #include "gc/g1/concurrentMarkThread.inline.hpp" |
34 #include "gc/g1/concurrentMarkThread.inline.hpp" |
35 #include "gc/g1/g1Allocator.inline.hpp" |
35 #include "gc/g1/g1Allocator.inline.hpp" |
36 #include "gc/g1/g1CollectedHeap.inline.hpp" |
36 #include "gc/g1/g1CollectedHeap.inline.hpp" |
|
37 #include "gc/g1/g1CollectionSet.hpp" |
37 #include "gc/g1/g1CollectorPolicy.hpp" |
38 #include "gc/g1/g1CollectorPolicy.hpp" |
38 #include "gc/g1/g1CollectorState.hpp" |
39 #include "gc/g1/g1CollectorState.hpp" |
39 #include "gc/g1/g1EvacStats.inline.hpp" |
40 #include "gc/g1/g1EvacStats.inline.hpp" |
40 #include "gc/g1/g1GCPhaseTimes.hpp" |
41 #include "gc/g1/g1GCPhaseTimes.hpp" |
41 #include "gc/g1/g1HeapTransition.hpp" |
42 #include "gc/g1/g1HeapTransition.hpp" |
1300 |
1301 |
1301 // We may have added regions to the current incremental collection |
1302 // We may have added regions to the current incremental collection |
1302 // set between the last GC or pause and now. We need to clear the |
1303 // set between the last GC or pause and now. We need to clear the |
1303 // incremental collection set and then start rebuilding it afresh |
1304 // incremental collection set and then start rebuilding it afresh |
1304 // after this full GC. |
1305 // after this full GC. |
1305 abandon_collection_set(g1_policy()->inc_cset_head()); |
1306 abandon_collection_set(collection_set()->inc_head()); |
1306 g1_policy()->clear_incremental_cset(); |
1307 collection_set()->clear_incremental(); |
1307 g1_policy()->stop_incremental_cset_building(); |
1308 collection_set()->stop_incremental_building(); |
1308 |
1309 |
1309 tear_down_region_sets(false /* free_list_only */); |
1310 tear_down_region_sets(false /* free_list_only */); |
1310 collector_state()->set_gcs_are_young(true); |
1311 collector_state()->set_gcs_are_young(true); |
1311 |
1312 |
1312 // See the comments in g1CollectedHeap.hpp and |
1313 // See the comments in g1CollectedHeap.hpp and |
1424 ((G1CMBitMap*) concurrent_mark()->prevMarkBitMap())->clearAll(); |
1425 ((G1CMBitMap*) concurrent_mark()->prevMarkBitMap())->clearAll(); |
1425 } |
1426 } |
1426 _verifier->check_bitmaps("Full GC End"); |
1427 _verifier->check_bitmaps("Full GC End"); |
1427 |
1428 |
1428 // Start a new incremental collection set for the next pause |
1429 // Start a new incremental collection set for the next pause |
1429 assert(g1_policy()->collection_set() == NULL, "must be"); |
1430 assert(collection_set()->head() == NULL, "must be"); |
1430 g1_policy()->start_incremental_cset_building(); |
1431 collection_set()->start_incremental_building(); |
1431 |
1432 |
1432 clear_cset_fast_test(); |
1433 clear_cset_fast_test(); |
1433 |
1434 |
1434 _allocator->init_mutator_alloc_region(); |
1435 _allocator->init_mutator_alloc_region(); |
1435 |
1436 |
1739 // Public methods. |
1740 // Public methods. |
1740 |
1741 |
1741 G1CollectedHeap::G1CollectedHeap(G1CollectorPolicy* policy_) : |
1742 G1CollectedHeap::G1CollectedHeap(G1CollectorPolicy* policy_) : |
1742 CollectedHeap(), |
1743 CollectedHeap(), |
1743 _g1_policy(policy_), |
1744 _g1_policy(policy_), |
|
1745 _collection_set(this), |
1744 _dirty_card_queue_set(false), |
1746 _dirty_card_queue_set(false), |
1745 _is_alive_closure_cm(this), |
1747 _is_alive_closure_cm(this), |
1746 _is_alive_closure_stw(this), |
1748 _is_alive_closure_stw(this), |
1747 _ref_processor_cm(NULL), |
1749 _ref_processor_cm(NULL), |
1748 _ref_processor_stw(NULL), |
1750 _ref_processor_stw(NULL), |
2543 // If we have: |
2545 // If we have: |
2544 // n collection set regions |
2546 // n collection set regions |
2545 // p threads |
2547 // p threads |
2546 // Then thread t will start at region floor ((t * n) / p) |
2548 // Then thread t will start at region floor ((t * n) / p) |
2547 |
2549 |
2548 result = g1_policy()->collection_set(); |
2550 result = collection_set()->head(); |
2549 uint cs_size = g1_policy()->cset_region_length(); |
2551 uint cs_size = collection_set()->region_length(); |
2550 uint active_workers = workers()->active_workers(); |
2552 uint active_workers = workers()->active_workers(); |
2551 |
2553 |
2552 uint end_ind = (cs_size * worker_i) / active_workers; |
2554 uint end_ind = (cs_size * worker_i) / active_workers; |
2553 uint start_ind = 0; |
2555 uint start_ind = 0; |
2554 |
2556 |
2575 _worker_cset_start_region_time_stamp[worker_i] = gc_time_stamp; |
2577 _worker_cset_start_region_time_stamp[worker_i] = gc_time_stamp; |
2576 return result; |
2578 return result; |
2577 } |
2579 } |
2578 |
2580 |
2579 void G1CollectedHeap::collection_set_iterate(HeapRegionClosure* cl) { |
2581 void G1CollectedHeap::collection_set_iterate(HeapRegionClosure* cl) { |
2580 HeapRegion* r = g1_policy()->collection_set(); |
2582 HeapRegion* r = collection_set()->head(); |
2581 while (r != NULL) { |
2583 while (r != NULL) { |
2582 HeapRegion* next = r->next_in_collection_set(); |
2584 HeapRegion* next = r->next_in_collection_set(); |
2583 if (cl->doHeapRegion(r)) { |
2585 if (cl->doHeapRegion(r)) { |
2584 cl->incomplete(); |
2586 cl->incomplete(); |
2585 return; |
2587 return; |
3334 |
3336 |
3335 if (collector_state()->during_initial_mark_pause()) { |
3337 if (collector_state()->during_initial_mark_pause()) { |
3336 concurrent_mark()->checkpointRootsInitialPre(); |
3338 concurrent_mark()->checkpointRootsInitialPre(); |
3337 } |
3339 } |
3338 |
3340 |
3339 double time_remaining_ms = g1_policy()->finalize_young_cset_part(target_pause_time_ms); |
3341 g1_policy()->finalize_collection_set(target_pause_time_ms); |
3340 g1_policy()->finalize_old_cset_part(time_remaining_ms); |
3342 |
3341 |
3343 evacuation_info.set_collectionset_regions(collection_set()->region_length()); |
3342 evacuation_info.set_collectionset_regions(g1_policy()->cset_region_length()); |
|
3343 |
3344 |
3344 // Make sure the remembered sets are up to date. This needs to be |
3345 // Make sure the remembered sets are up to date. This needs to be |
3345 // done before register_humongous_regions_with_cset(), because the |
3346 // done before register_humongous_regions_with_cset(), because the |
3346 // remembered sets are used there to choose eager reclaim candidates. |
3347 // remembered sets are used there to choose eager reclaim candidates. |
3347 // If the remembered sets are not up to date we might miss some |
3348 // If the remembered sets are not up to date we might miss some |
3356 // We call this after finalize_cset() to |
3357 // We call this after finalize_cset() to |
3357 // ensure that the CSet has been finalized. |
3358 // ensure that the CSet has been finalized. |
3358 _cm->verify_no_cset_oops(); |
3359 _cm->verify_no_cset_oops(); |
3359 |
3360 |
3360 if (_hr_printer.is_active()) { |
3361 if (_hr_printer.is_active()) { |
3361 HeapRegion* hr = g1_policy()->collection_set(); |
3362 HeapRegion* hr = collection_set()->head(); |
3362 while (hr != NULL) { |
3363 while (hr != NULL) { |
3363 _hr_printer.cset(hr); |
3364 _hr_printer.cset(hr); |
3364 hr = hr->next_in_collection_set(); |
3365 hr = hr->next_in_collection_set(); |
3365 } |
3366 } |
3366 } |
3367 } |
3371 #endif // ASSERT |
3372 #endif // ASSERT |
3372 |
3373 |
3373 // Initialize the GC alloc regions. |
3374 // Initialize the GC alloc regions. |
3374 _allocator->init_gc_alloc_regions(evacuation_info); |
3375 _allocator->init_gc_alloc_regions(evacuation_info); |
3375 |
3376 |
3376 G1ParScanThreadStateSet per_thread_states(this, workers()->active_workers(), g1_policy()->young_cset_region_length()); |
3377 G1ParScanThreadStateSet per_thread_states(this, workers()->active_workers(), collection_set()->young_region_length()); |
3377 pre_evacuate_collection_set(); |
3378 pre_evacuate_collection_set(); |
3378 |
3379 |
3379 // Actually do the work... |
3380 // Actually do the work... |
3380 evacuate_collection_set(evacuation_info, &per_thread_states); |
3381 evacuate_collection_set(evacuation_info, &per_thread_states); |
3381 |
3382 |
3382 post_evacuate_collection_set(evacuation_info, &per_thread_states); |
3383 post_evacuate_collection_set(evacuation_info, &per_thread_states); |
3383 |
3384 |
3384 const size_t* surviving_young_words = per_thread_states.surviving_young_words(); |
3385 const size_t* surviving_young_words = per_thread_states.surviving_young_words(); |
3385 free_collection_set(g1_policy()->collection_set(), evacuation_info, surviving_young_words); |
3386 free_collection_set(collection_set()->head(), evacuation_info, surviving_young_words); |
3386 |
3387 |
3387 eagerly_reclaim_humongous_regions(); |
3388 eagerly_reclaim_humongous_regions(); |
3388 |
3389 |
3389 g1_policy()->clear_collection_set(); |
3390 collection_set()->clear_head(); |
3390 |
3391 |
3391 record_obj_copy_mem_stats(); |
3392 record_obj_copy_mem_stats(); |
3392 _survivor_evac_stats.adjust_desired_plab_sz(); |
3393 _survivor_evac_stats.adjust_desired_plab_sz(); |
3393 _old_evac_stats.adjust_desired_plab_sz(); |
3394 _old_evac_stats.adjust_desired_plab_sz(); |
3394 |
3395 |
3395 // Start a new incremental collection set for the next pause. |
3396 // Start a new incremental collection set for the next pause. |
3396 g1_policy()->start_incremental_cset_building(); |
3397 collection_set()->start_incremental_building(); |
3397 |
3398 |
3398 clear_cset_fast_test(); |
3399 clear_cset_fast_test(); |
3399 |
3400 |
3400 // Don't check the whole heap at this point as the |
3401 // Don't check the whole heap at this point as the |
3401 // GC alloc regions from this pause have been tagged |
3402 // GC alloc regions from this pause have been tagged |
3466 double sample_end_time_sec = os::elapsedTime(); |
3467 double sample_end_time_sec = os::elapsedTime(); |
3467 double pause_time_ms = (sample_end_time_sec - sample_start_time_sec) * MILLIUNITS; |
3468 double pause_time_ms = (sample_end_time_sec - sample_start_time_sec) * MILLIUNITS; |
3468 size_t total_cards_scanned = per_thread_states.total_cards_scanned(); |
3469 size_t total_cards_scanned = per_thread_states.total_cards_scanned(); |
3469 g1_policy()->record_collection_pause_end(pause_time_ms, total_cards_scanned, heap_used_bytes_before_gc); |
3470 g1_policy()->record_collection_pause_end(pause_time_ms, total_cards_scanned, heap_used_bytes_before_gc); |
3470 |
3471 |
3471 evacuation_info.set_collectionset_used_before(g1_policy()->collection_set_bytes_used_before()); |
3472 evacuation_info.set_collectionset_used_before(collection_set()->bytes_used_before()); |
3472 evacuation_info.set_bytes_copied(g1_policy()->bytes_copied_during_gc()); |
3473 evacuation_info.set_bytes_copied(g1_policy()->bytes_copied_during_gc()); |
3473 |
3474 |
3474 MemoryService::track_memory_usage(); |
3475 MemoryService::track_memory_usage(); |
3475 |
3476 |
3476 // In prepare_for_verify() below we'll need to scan the deferred |
3477 // In prepare_for_verify() below we'll need to scan the deferred |
4907 clear_in_cset(cur); |
4908 clear_in_cset(cur); |
4908 |
4909 |
4909 if (cur->is_young()) { |
4910 if (cur->is_young()) { |
4910 int index = cur->young_index_in_cset(); |
4911 int index = cur->young_index_in_cset(); |
4911 assert(index != -1, "invariant"); |
4912 assert(index != -1, "invariant"); |
4912 assert((uint) index < policy->young_cset_region_length(), "invariant"); |
4913 assert((uint) index < collection_set()->young_region_length(), "invariant"); |
4913 size_t words_survived = surviving_young_words[index]; |
4914 size_t words_survived = surviving_young_words[index]; |
4914 cur->record_surv_words_in_group(words_survived); |
4915 cur->record_surv_words_in_group(words_survived); |
4915 |
4916 |
4916 // At this point the we have 'popped' cur from the collection set |
4917 // At this point the we have 'popped' cur from the collection set |
4917 // (linked via next_in_collection_set()) but it is still in the |
4918 // (linked via next_in_collection_set()) but it is still in the |
5380 void G1CollectedHeap::retire_mutator_alloc_region(HeapRegion* alloc_region, |
5381 void G1CollectedHeap::retire_mutator_alloc_region(HeapRegion* alloc_region, |
5381 size_t allocated_bytes) { |
5382 size_t allocated_bytes) { |
5382 assert_heap_locked_or_at_safepoint(true /* should_be_vm_thread */); |
5383 assert_heap_locked_or_at_safepoint(true /* should_be_vm_thread */); |
5383 assert(alloc_region->is_eden(), "all mutator alloc regions should be eden"); |
5384 assert(alloc_region->is_eden(), "all mutator alloc regions should be eden"); |
5384 |
5385 |
5385 g1_policy()->add_region_to_incremental_cset_lhs(alloc_region); |
5386 collection_set()->add_eden_region(alloc_region); |
5386 increase_used(allocated_bytes); |
5387 increase_used(allocated_bytes); |
5387 _hr_printer.retire(alloc_region); |
5388 _hr_printer.retire(alloc_region); |
5388 // We update the eden sizes here, when the region is retired, |
5389 // We update the eden sizes here, when the region is retired, |
5389 // instead of when it's allocated, since this is the point that its |
5390 // instead of when it's allocated, since this is the point that its |
5390 // used space has been recored in _summary_bytes_used. |
5391 // used space has been recored in _summary_bytes_used. |