src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp

changeset 1428
54b3b351d6f9
parent 1424
148e5441d916
parent 1377
2c79770d1f6e
child 1454
035d2e036a9b
equal deleted inserted replaced
1427:6a8ccac44f41 1428:54b3b351d6f9
22 * 22 *
23 */ 23 */
24 24
25 #include "incls/_precompiled.incl" 25 #include "incls/_precompiled.incl"
26 #include "incls/_g1CollectedHeap.cpp.incl" 26 #include "incls/_g1CollectedHeap.cpp.incl"
27
28 size_t G1CollectedHeap::_humongous_object_threshold_in_words = 0;
27 29
28 // turn it on so that the contents of the young list (scan-only / 30 // turn it on so that the contents of the young list (scan-only /
29 // to-be-collected) are printed at "strategic" points before / during 31 // to-be-collected) are printed at "strategic" points before / during
30 // / after the collection --- this is useful for debugging 32 // / after the collection --- this is useful for debugging
31 #define SCAN_ONLY_VERBOSE 0 33 #define SCAN_ONLY_VERBOSE 0
925 gclog_or_tty->date_stamp(PrintGC && PrintGCDateStamps); 927 gclog_or_tty->date_stamp(PrintGC && PrintGCDateStamps);
926 TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty); 928 TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty);
927 TraceTime t(full ? "Full GC (System.gc())" : "Full GC", PrintGC, true, gclog_or_tty); 929 TraceTime t(full ? "Full GC (System.gc())" : "Full GC", PrintGC, true, gclog_or_tty);
928 930
929 double start = os::elapsedTime(); 931 double start = os::elapsedTime();
930 GCOverheadReporter::recordSTWStart(start);
931 g1_policy()->record_full_collection_start(); 932 g1_policy()->record_full_collection_start();
932 933
933 gc_prologue(true); 934 gc_prologue(true);
934 increment_total_collections(true /* full gc */); 935 increment_total_collections(true /* full gc */);
935 936
1047 // Ask the permanent generation to adjust size for full collections 1048 // Ask the permanent generation to adjust size for full collections
1048 perm()->compute_new_size(); 1049 perm()->compute_new_size();
1049 } 1050 }
1050 1051
1051 double end = os::elapsedTime(); 1052 double end = os::elapsedTime();
1052 GCOverheadReporter::recordSTWEnd(end);
1053 g1_policy()->record_full_collection_end(); 1053 g1_policy()->record_full_collection_end();
1054 1054
1055 #ifdef TRACESPINNING 1055 #ifdef TRACESPINNING
1056 ParallelTaskTerminator::print_termination_counts(); 1056 ParallelTaskTerminator::print_termination_counts();
1057 #endif 1057 #endif
1394 _dirty_cards_region_list(NULL) { 1394 _dirty_cards_region_list(NULL) {
1395 _g1h = this; // To catch bugs. 1395 _g1h = this; // To catch bugs.
1396 if (_process_strong_tasks == NULL || !_process_strong_tasks->valid()) { 1396 if (_process_strong_tasks == NULL || !_process_strong_tasks->valid()) {
1397 vm_exit_during_initialization("Failed necessary allocation."); 1397 vm_exit_during_initialization("Failed necessary allocation.");
1398 } 1398 }
1399
1400 _humongous_object_threshold_in_words = HeapRegion::GrainWords / 2;
1401
1399 int n_queues = MAX2((int)ParallelGCThreads, 1); 1402 int n_queues = MAX2((int)ParallelGCThreads, 1);
1400 _task_queues = new RefToScanQueueSet(n_queues); 1403 _task_queues = new RefToScanQueueSet(n_queues);
1401 1404
1402 int n_rem_sets = HeapRegionRemSet::num_par_rem_sets(); 1405 int n_rem_sets = HeapRegionRemSet::num_par_rem_sets();
1403 assert(n_rem_sets > 0, "Invariant."); 1406 assert(n_rem_sets > 0, "Invariant.");
1546 // 6843694 - ensure that the maximum region index can fit 1549 // 6843694 - ensure that the maximum region index can fit
1547 // in the remembered set structures. 1550 // in the remembered set structures.
1548 const size_t max_region_idx = ((size_t)1 << (sizeof(RegionIdx_t)*BitsPerByte-1)) - 1; 1551 const size_t max_region_idx = ((size_t)1 << (sizeof(RegionIdx_t)*BitsPerByte-1)) - 1;
1549 guarantee((max_regions() - 1) <= max_region_idx, "too many regions"); 1552 guarantee((max_regions() - 1) <= max_region_idx, "too many regions");
1550 1553
1551 const size_t cards_per_region = HeapRegion::GrainBytes >> CardTableModRefBS::card_shift;
1552 size_t max_cards_per_region = ((size_t)1 << (sizeof(CardIdx_t)*BitsPerByte-1)) - 1; 1554 size_t max_cards_per_region = ((size_t)1 << (sizeof(CardIdx_t)*BitsPerByte-1)) - 1;
1553 guarantee(cards_per_region < max_cards_per_region, "too many cards per region"); 1555 guarantee(HeapRegion::CardsPerRegion > 0, "make sure it's initialized");
1556 guarantee((size_t) HeapRegion::CardsPerRegion < max_cards_per_region,
1557 "too many cards per region");
1554 1558
1555 _bot_shared = new G1BlockOffsetSharedArray(_reserved, 1559 _bot_shared = new G1BlockOffsetSharedArray(_reserved,
1556 heap_word_size(init_byte_size)); 1560 heap_word_size(init_byte_size));
1557 1561
1558 _g1h = this; 1562 _g1h = this;
1607 1611
1608 _gc_alloc_region_list = NULL; 1612 _gc_alloc_region_list = NULL;
1609 1613
1610 // Do later initialization work for concurrent refinement. 1614 // Do later initialization work for concurrent refinement.
1611 _cg1r->init(); 1615 _cg1r->init();
1612
1613 const char* group_names[] = { "CR", "ZF", "CM", "CL" };
1614 GCOverheadReporter::initGCOverheadReporter(4, group_names);
1615 1616
1616 return JNI_OK; 1617 return JNI_OK;
1617 } 1618 }
1618 1619
1619 void G1CollectedHeap::ref_processing_init() { 1620 void G1CollectedHeap::ref_processing_init() {
2432 if (G1SummarizeZFStats) { 2433 if (G1SummarizeZFStats) {
2433 ConcurrentZFThread::print_summary_info(); 2434 ConcurrentZFThread::print_summary_info();
2434 } 2435 }
2435 g1_policy()->print_yg_surv_rate_info(); 2436 g1_policy()->print_yg_surv_rate_info();
2436 2437
2437 GCOverheadReporter::printGCOverhead();
2438
2439 SpecializationStats::print(); 2438 SpecializationStats::print();
2440 } 2439 }
2441 2440
2442 2441
2443 int G1CollectedHeap::addr_to_arena_id(void* addr) const { 2442 int G1CollectedHeap::addr_to_arena_id(void* addr) const {
2670 abandon_cur_alloc_region(); 2669 abandon_cur_alloc_region();
2671 2670
2672 // The elapsed time induced by the start time below deliberately elides 2671 // The elapsed time induced by the start time below deliberately elides
2673 // the possible verification above. 2672 // the possible verification above.
2674 double start_time_sec = os::elapsedTime(); 2673 double start_time_sec = os::elapsedTime();
2675 GCOverheadReporter::recordSTWStart(start_time_sec);
2676 size_t start_used_bytes = used(); 2674 size_t start_used_bytes = used();
2677 2675
2678 g1_policy()->record_collection_pause_start(start_time_sec, 2676 g1_policy()->record_collection_pause_start(start_time_sec,
2679 start_used_bytes); 2677 start_used_bytes);
2680 2678
2747 FREE_C_HEAP_ARRAY(bool, _in_cset_fast_test_base); 2745 FREE_C_HEAP_ARRAY(bool, _in_cset_fast_test_base);
2748 // this is more for peace of mind; we're nulling them here and 2746 // this is more for peace of mind; we're nulling them here and
2749 // we're expecting them to be null at the beginning of the next GC 2747 // we're expecting them to be null at the beginning of the next GC
2750 _in_cset_fast_test = NULL; 2748 _in_cset_fast_test = NULL;
2751 _in_cset_fast_test_base = NULL; 2749 _in_cset_fast_test_base = NULL;
2752
2753 release_gc_alloc_regions(false /* totally */);
2754 2750
2755 cleanup_surviving_young_words(); 2751 cleanup_surviving_young_words();
2756 2752
2757 if (g1_policy()->in_young_gc_mode()) { 2753 if (g1_policy()->in_young_gc_mode()) {
2758 _young_list->reset_sampled_info(); 2754 _young_list->reset_sampled_info();
2799 #endif // SCAN_ONLY_VERBOSE 2795 #endif // SCAN_ONLY_VERBOSE
2800 2796
2801 double end_time_sec = os::elapsedTime(); 2797 double end_time_sec = os::elapsedTime();
2802 double pause_time_ms = (end_time_sec - start_time_sec) * MILLIUNITS; 2798 double pause_time_ms = (end_time_sec - start_time_sec) * MILLIUNITS;
2803 g1_policy()->record_pause_time_ms(pause_time_ms); 2799 g1_policy()->record_pause_time_ms(pause_time_ms);
2804 GCOverheadReporter::recordSTWEnd(end_time_sec);
2805 g1_policy()->record_collection_pause_end(abandoned); 2800 g1_policy()->record_collection_pause_end(abandoned);
2806 2801
2807 assert(regions_accounted_for(), "Region leakage."); 2802 assert(regions_accounted_for(), "Region leakage.");
2808 2803
2809 if (VerifyAfterGC && total_collections() >= VerifyGCStartAt) { 2804 if (VerifyAfterGC && total_collections() >= VerifyGCStartAt) {
4150 { 4145 {
4151 G1IsAliveClosure is_alive(this); 4146 G1IsAliveClosure is_alive(this);
4152 G1KeepAliveClosure keep_alive(this); 4147 G1KeepAliveClosure keep_alive(this);
4153 JNIHandles::weak_oops_do(&is_alive, &keep_alive); 4148 JNIHandles::weak_oops_do(&is_alive, &keep_alive);
4154 } 4149 }
4150 release_gc_alloc_regions(false /* totally */);
4155 g1_rem_set()->cleanup_after_oops_into_collection_set_do(); 4151 g1_rem_set()->cleanup_after_oops_into_collection_set_do();
4156 4152
4157 concurrent_g1_refine()->clear_hot_cache(); 4153 concurrent_g1_refine()->clear_hot_cache();
4158 concurrent_g1_refine()->set_use_cache(true); 4154 concurrent_g1_refine()->set_use_cache(true);
4159 4155
4283 4279
4284 4280
4285 class G1ParCleanupCTTask : public AbstractGangTask { 4281 class G1ParCleanupCTTask : public AbstractGangTask {
4286 CardTableModRefBS* _ct_bs; 4282 CardTableModRefBS* _ct_bs;
4287 G1CollectedHeap* _g1h; 4283 G1CollectedHeap* _g1h;
4284 HeapRegion* volatile _so_head;
4285 HeapRegion* volatile _su_head;
4288 public: 4286 public:
4289 G1ParCleanupCTTask(CardTableModRefBS* ct_bs, 4287 G1ParCleanupCTTask(CardTableModRefBS* ct_bs,
4290 G1CollectedHeap* g1h) : 4288 G1CollectedHeap* g1h,
4289 HeapRegion* scan_only_list,
4290 HeapRegion* survivor_list) :
4291 AbstractGangTask("G1 Par Cleanup CT Task"), 4291 AbstractGangTask("G1 Par Cleanup CT Task"),
4292 _ct_bs(ct_bs), 4292 _ct_bs(ct_bs),
4293 _g1h(g1h) 4293 _g1h(g1h),
4294 _so_head(scan_only_list),
4295 _su_head(survivor_list)
4294 { } 4296 { }
4295 4297
4296 void work(int i) { 4298 void work(int i) {
4297 HeapRegion* r; 4299 HeapRegion* r;
4298 while (r = _g1h->pop_dirty_cards_region()) { 4300 while (r = _g1h->pop_dirty_cards_region()) {
4299 clear_cards(r); 4301 clear_cards(r);
4300 } 4302 }
4301 } 4303 // Redirty the cards of the scan-only and survivor regions.
4304 dirty_list(&this->_so_head);
4305 dirty_list(&this->_su_head);
4306 }
4307
4302 void clear_cards(HeapRegion* r) { 4308 void clear_cards(HeapRegion* r) {
4303 // Cards for Survivor and Scan-Only regions will be dirtied later. 4309 // Cards for Survivor and Scan-Only regions will be dirtied later.
4304 if (!r->is_scan_only() && !r->is_survivor()) { 4310 if (!r->is_scan_only() && !r->is_survivor()) {
4305 _ct_bs->clear(MemRegion(r->bottom(), r->end())); 4311 _ct_bs->clear(MemRegion(r->bottom(), r->end()));
4306 } 4312 }
4307 } 4313 }
4314
4315 void dirty_list(HeapRegion* volatile * head_ptr) {
4316 HeapRegion* head;
4317 do {
4318 // Pop region off the list.
4319 head = *head_ptr;
4320 if (head != NULL) {
4321 HeapRegion* r = (HeapRegion*)
4322 Atomic::cmpxchg_ptr(head->get_next_young_region(), head_ptr, head);
4323 if (r == head) {
4324 assert(!r->isHumongous(), "Humongous regions shouldn't be on survivor list");
4325 _ct_bs->dirty(MemRegion(r->bottom(), r->end()));
4326 }
4327 }
4328 } while (*head_ptr != NULL);
4329 }
4308 }; 4330 };
4309 4331
4332
4333 #ifndef PRODUCT
4334 class G1VerifyCardTableCleanup: public HeapRegionClosure {
4335 CardTableModRefBS* _ct_bs;
4336 public:
4337 G1VerifyCardTableCleanup(CardTableModRefBS* ct_bs)
4338 : _ct_bs(ct_bs)
4339 { }
4340 virtual bool doHeapRegion(HeapRegion* r)
4341 {
4342 MemRegion mr(r->bottom(), r->end());
4343 if (r->is_scan_only() || r->is_survivor()) {
4344 _ct_bs->verify_dirty_region(mr);
4345 } else {
4346 _ct_bs->verify_clean_region(mr);
4347 }
4348 return false;
4349 }
4350 };
4351 #endif
4310 4352
4311 void G1CollectedHeap::cleanUpCardTable() { 4353 void G1CollectedHeap::cleanUpCardTable() {
4312 CardTableModRefBS* ct_bs = (CardTableModRefBS*) (barrier_set()); 4354 CardTableModRefBS* ct_bs = (CardTableModRefBS*) (barrier_set());
4313 double start = os::elapsedTime(); 4355 double start = os::elapsedTime();
4314 4356
4315 // Iterate over the dirty cards region list. 4357 // Iterate over the dirty cards region list.
4316 G1ParCleanupCTTask cleanup_task(ct_bs, this); 4358 G1ParCleanupCTTask cleanup_task(ct_bs, this,
4359 _young_list->first_scan_only_region(),
4360 _young_list->first_survivor_region());
4317 if (ParallelGCThreads > 0) { 4361 if (ParallelGCThreads > 0) {
4318 set_par_threads(workers()->total_workers()); 4362 set_par_threads(workers()->total_workers());
4319 workers()->run_task(&cleanup_task); 4363 workers()->run_task(&cleanup_task);
4320 set_par_threads(0); 4364 set_par_threads(0);
4321 } else { 4365 } else {
4327 // The last region. 4371 // The last region.
4328 _dirty_cards_region_list = NULL; 4372 _dirty_cards_region_list = NULL;
4329 } 4373 }
4330 r->set_next_dirty_cards_region(NULL); 4374 r->set_next_dirty_cards_region(NULL);
4331 } 4375 }
4332 } 4376 // now, redirty the cards of the scan-only and survivor regions
4333 // now, redirty the cards of the scan-only and survivor regions 4377 // (it seemed faster to do it this way, instead of iterating over
4334 // (it seemed faster to do it this way, instead of iterating over 4378 // all regions and then clearing / dirtying as appropriate)
4335 // all regions and then clearing / dirtying as appropriate) 4379 dirtyCardsForYoungRegions(ct_bs, _young_list->first_scan_only_region());
4336 dirtyCardsForYoungRegions(ct_bs, _young_list->first_scan_only_region()); 4380 dirtyCardsForYoungRegions(ct_bs, _young_list->first_survivor_region());
4337 dirtyCardsForYoungRegions(ct_bs, _young_list->first_survivor_region()); 4381 }
4338
4339 double elapsed = os::elapsedTime() - start; 4382 double elapsed = os::elapsedTime() - start;
4340 g1_policy()->record_clear_ct_time( elapsed * 1000.0); 4383 g1_policy()->record_clear_ct_time( elapsed * 1000.0);
4341 } 4384 #ifndef PRODUCT
4342 4385 if (G1VerifyCTCleanup || VerifyAfterGC) {
4386 G1VerifyCardTableCleanup cleanup_verifier(ct_bs);
4387 heap_region_iterate(&cleanup_verifier);
4388 }
4389 #endif
4390 }
4343 4391
4344 void G1CollectedHeap::do_collection_pause_if_appropriate(size_t word_size) { 4392 void G1CollectedHeap::do_collection_pause_if_appropriate(size_t word_size) {
4345 if (g1_policy()->should_do_collection_pause(word_size)) { 4393 if (g1_policy()->should_do_collection_pause(word_size)) {
4346 do_collection_pause(); 4394 do_collection_pause();
4347 } 4395 }
5031 return is_in_permanent(p); 5079 return is_in_permanent(p);
5032 } else { 5080 } else {
5033 return hr->is_in(p); 5081 return hr->is_in(p);
5034 } 5082 }
5035 } 5083 }
5036 #endif // PRODUCT 5084 #endif // !PRODUCT
5037 5085
5038 void G1CollectedHeap::g1_unimplemented() { 5086 void G1CollectedHeap::g1_unimplemented() {
5039 // Unimplemented(); 5087 // Unimplemented();
5040 } 5088 }

mercurial