167 return new HeapRegion(hrs_index, bot(), mr); |
167 return new HeapRegion(hrs_index, bot(), mr); |
168 } |
168 } |
169 |
169 |
170 // Private methods. |
170 // Private methods. |
171 |
171 |
172 HeapRegion* G1CollectedHeap::new_region(size_t word_size, HeapRegionType type, bool do_expand) { |
172 HeapRegion* G1CollectedHeap::new_region(size_t word_size, |
|
173 HeapRegionType type, |
|
174 bool do_expand, |
|
175 uint node_index) { |
173 assert(!is_humongous(word_size) || word_size <= HeapRegion::GrainWords, |
176 assert(!is_humongous(word_size) || word_size <= HeapRegion::GrainWords, |
174 "the only time we use this to allocate a humongous region is " |
177 "the only time we use this to allocate a humongous region is " |
175 "when we are allocating a single humongous region"); |
178 "when we are allocating a single humongous region"); |
176 |
179 |
177 HeapRegion* res = _hrm->allocate_free_region(type); |
180 HeapRegion* res = _hrm->allocate_free_region(type, node_index); |
178 |
181 |
179 if (res == NULL && do_expand && _expand_heap_after_alloc_failure) { |
182 if (res == NULL && do_expand && _expand_heap_after_alloc_failure) { |
180 // Currently, only attempts to allocate GC alloc regions set |
183 // Currently, only attempts to allocate GC alloc regions set |
181 // do_expand to true. So, we should only reach here during a |
184 // do_expand to true. So, we should only reach here during a |
182 // safepoint. If this assumption changes we might have to |
185 // safepoint. If this assumption changes we might have to |
184 assert(SafepointSynchronize::is_at_safepoint(), "invariant"); |
187 assert(SafepointSynchronize::is_at_safepoint(), "invariant"); |
185 |
188 |
186 log_debug(gc, ergo, heap)("Attempt heap expansion (region allocation request failed). Allocation request: " SIZE_FORMAT "B", |
189 log_debug(gc, ergo, heap)("Attempt heap expansion (region allocation request failed). Allocation request: " SIZE_FORMAT "B", |
187 word_size * HeapWordSize); |
190 word_size * HeapWordSize); |
188 |
191 |
189 if (expand(word_size * HeapWordSize)) { |
192 assert(word_size * HeapWordSize < HeapRegion::GrainBytes, |
190 // Given that expand() succeeded in expanding the heap, and we |
193 "This kind of expansion should never be more than one region. Size: " SIZE_FORMAT, |
|
194 word_size * HeapWordSize); |
|
195 if (expand_single_region(node_index)) { |
|
196 // Given that expand_single_region() succeeded in expanding the heap, and we |
191 // always expand the heap by an amount aligned to the heap |
197 // always expand the heap by an amount aligned to the heap |
192 // region size, the free list should in theory not be empty. |
198 // region size, the free list should in theory not be empty. |
193 // In either case allocate_free_region() will check for NULL. |
199 // In either case allocate_free_region() will check for NULL. |
194 res = _hrm->allocate_free_region(type); |
200 res = _hrm->allocate_free_region(type, node_index); |
195 } else { |
201 } else { |
196 _expand_heap_after_alloc_failure = false; |
202 _expand_heap_after_alloc_failure = false; |
197 } |
203 } |
198 } |
204 } |
199 return res; |
205 return res; |
1018 concurrent_mark()->concurrent_cycle_abort(); |
1024 concurrent_mark()->concurrent_cycle_abort(); |
1019 } |
1025 } |
1020 |
1026 |
1021 void G1CollectedHeap::prepare_heap_for_full_collection() { |
1027 void G1CollectedHeap::prepare_heap_for_full_collection() { |
1022 // Make sure we'll choose a new allocation region afterwards. |
1028 // Make sure we'll choose a new allocation region afterwards. |
1023 _allocator->release_mutator_alloc_region(); |
1029 _allocator->release_mutator_alloc_regions(); |
1024 _allocator->abandon_gc_alloc_regions(); |
1030 _allocator->abandon_gc_alloc_regions(); |
1025 |
1031 |
1026 // We may have added regions to the current incremental collection |
1032 // We may have added regions to the current incremental collection |
1027 // set between the last GC or pause and now. We need to clear the |
1033 // set between the last GC or pause and now. We need to clear the |
1028 // incremental collection set and then start rebuilding it afresh |
1034 // incremental collection set and then start rebuilding it afresh |
1062 purge_code_root_memory(); |
1068 purge_code_root_memory(); |
1063 |
1069 |
1064 // Start a new incremental collection set for the next pause |
1070 // Start a new incremental collection set for the next pause |
1065 start_new_collection_set(); |
1071 start_new_collection_set(); |
1066 |
1072 |
1067 _allocator->init_mutator_alloc_region(); |
1073 _allocator->init_mutator_alloc_regions(); |
1068 |
1074 |
1069 // Post collection state updates. |
1075 // Post collection state updates. |
1070 MetaspaceGC::compute_new_size(); |
1076 MetaspaceGC::compute_new_size(); |
1071 } |
1077 } |
1072 |
1078 |
1379 } |
1385 } |
1380 } |
1386 } |
1381 return regions_to_expand > 0; |
1387 return regions_to_expand > 0; |
1382 } |
1388 } |
1383 |
1389 |
|
1390 bool G1CollectedHeap::expand_single_region(uint node_index) { |
|
1391 uint expanded_by = _hrm->expand_on_preferred_node(node_index); |
|
1392 |
|
1393 if (expanded_by == 0) { |
|
1394 assert(is_maximal_no_gc(), "Should be no regions left, available: %u", _hrm->available()); |
|
1395 log_debug(gc, ergo, heap)("Did not expand the heap (heap already fully expanded)"); |
|
1396 return false; |
|
1397 } |
|
1398 |
|
1399 policy()->record_new_heap_size(num_regions()); |
|
1400 return true; |
|
1401 } |
|
1402 |
1384 void G1CollectedHeap::shrink_helper(size_t shrink_bytes) { |
1403 void G1CollectedHeap::shrink_helper(size_t shrink_bytes) { |
1385 size_t aligned_shrink_bytes = |
1404 size_t aligned_shrink_bytes = |
1386 ReservedSpace::page_align_size_down(shrink_bytes); |
1405 ReservedSpace::page_align_size_down(shrink_bytes); |
1387 aligned_shrink_bytes = align_down(aligned_shrink_bytes, |
1406 aligned_shrink_bytes = align_down(aligned_shrink_bytes, |
1388 HeapRegion::GrainBytes); |
1407 HeapRegion::GrainBytes); |
1389 uint num_regions_to_remove = (uint)(shrink_bytes / HeapRegion::GrainBytes); |
1408 uint num_regions_to_remove = (uint)(shrink_bytes / HeapRegion::GrainBytes); |
1390 |
1409 |
1391 uint num_regions_removed = _hrm->shrink_by(num_regions_to_remove); |
1410 uint num_regions_removed = _hrm->shrink_by(num_regions_to_remove); |
1392 size_t shrunk_bytes = num_regions_removed * HeapRegion::GrainBytes; |
1411 size_t shrunk_bytes = num_regions_removed * HeapRegion::GrainBytes; |
1393 |
|
1394 |
1412 |
1395 log_debug(gc, ergo, heap)("Shrink the heap. requested shrinking amount: " SIZE_FORMAT "B aligned shrinking amount: " SIZE_FORMAT "B attempted shrinking amount: " SIZE_FORMAT "B", |
1413 log_debug(gc, ergo, heap)("Shrink the heap. requested shrinking amount: " SIZE_FORMAT "B aligned shrinking amount: " SIZE_FORMAT "B attempted shrinking amount: " SIZE_FORMAT "B", |
1396 shrink_bytes, aligned_shrink_bytes, shrunk_bytes); |
1414 shrink_bytes, aligned_shrink_bytes, shrunk_bytes); |
1397 if (num_regions_removed > 0) { |
1415 if (num_regions_removed > 0) { |
1398 policy()->record_new_heap_size(num_regions()); |
1416 policy()->record_new_heap_size(num_regions()); |
1491 _old_set("Old Region Set", new OldRegionSetChecker()), |
1509 _old_set("Old Region Set", new OldRegionSetChecker()), |
1492 _archive_set("Archive Region Set", new ArchiveRegionSetChecker()), |
1510 _archive_set("Archive Region Set", new ArchiveRegionSetChecker()), |
1493 _humongous_set("Humongous Region Set", new HumongousRegionSetChecker()), |
1511 _humongous_set("Humongous Region Set", new HumongousRegionSetChecker()), |
1494 _bot(NULL), |
1512 _bot(NULL), |
1495 _listener(), |
1513 _listener(), |
|
1514 _numa(G1NUMA::create()), |
1496 _hrm(NULL), |
1515 _hrm(NULL), |
1497 _allocator(NULL), |
1516 _allocator(NULL), |
1498 _verifier(NULL), |
1517 _verifier(NULL), |
1499 _summary_bytes_used(0), |
1518 _summary_bytes_used(0), |
1500 _archive_allocator(NULL), |
1519 _archive_allocator(NULL), |
1773 if (_workers == NULL) { |
1792 if (_workers == NULL) { |
1774 return JNI_ENOMEM; |
1793 return JNI_ENOMEM; |
1775 } |
1794 } |
1776 _workers->initialize_workers(); |
1795 _workers->initialize_workers(); |
1777 |
1796 |
|
1797 _numa->set_region_info(HeapRegion::GrainBytes, page_size); |
|
1798 |
1778 // Create the G1ConcurrentMark data structure and thread. |
1799 // Create the G1ConcurrentMark data structure and thread. |
1779 // (Must do this late, so that "max_regions" is defined.) |
1800 // (Must do this late, so that "max_regions" is defined.) |
1780 _cm = new G1ConcurrentMark(this, prev_bitmap_storage, next_bitmap_storage); |
1801 _cm = new G1ConcurrentMark(this, prev_bitmap_storage, next_bitmap_storage); |
1781 if (_cm == NULL || !_cm->completed_initialization()) { |
1802 if (_cm == NULL || !_cm->completed_initialization()) { |
1782 vm_shutdown_during_initialization("Could not create/initialize G1ConcurrentMark"); |
1803 vm_shutdown_during_initialization("Could not create/initialize G1ConcurrentMark"); |
1820 dummy_region->set_eden(); |
1841 dummy_region->set_eden(); |
1821 // Make sure it's full. |
1842 // Make sure it's full. |
1822 dummy_region->set_top(dummy_region->end()); |
1843 dummy_region->set_top(dummy_region->end()); |
1823 G1AllocRegion::setup(this, dummy_region); |
1844 G1AllocRegion::setup(this, dummy_region); |
1824 |
1845 |
1825 _allocator->init_mutator_alloc_region(); |
1846 _allocator->init_mutator_alloc_regions(); |
1826 |
1847 |
1827 // Do create of the monitoring and management support so that |
1848 // Do create of the monitoring and management support so that |
1828 // values in the heap have been properly initialized. |
1849 // values in the heap have been properly initialized. |
1829 _g1mm = new G1MonitoringSupport(this); |
1850 _g1mm = new G1MonitoringSupport(this); |
1830 |
1851 |
3003 |
3024 |
3004 policy()->record_collection_pause_start(sample_start_time_sec); |
3025 policy()->record_collection_pause_start(sample_start_time_sec); |
3005 |
3026 |
3006 // Forget the current allocation region (we might even choose it to be part |
3027 // Forget the current allocation region (we might even choose it to be part |
3007 // of the collection set!). |
3028 // of the collection set!). |
3008 _allocator->release_mutator_alloc_region(); |
3029 _allocator->release_mutator_alloc_regions(); |
3009 |
3030 |
3010 calculate_collection_set(evacuation_info, target_pause_time_ms); |
3031 calculate_collection_set(evacuation_info, target_pause_time_ms); |
3011 |
3032 |
3012 G1RedirtyCardsQueueSet rdcqs(G1BarrierSet::dirty_card_queue_set().allocator()); |
3033 G1RedirtyCardsQueueSet rdcqs(G1BarrierSet::dirty_card_queue_set().allocator()); |
3013 G1ParScanThreadStateSet per_thread_states(this, |
3034 G1ParScanThreadStateSet per_thread_states(this, |
3040 // the current thread has completed its logging output. |
3061 // the current thread has completed its logging output. |
3041 } |
3062 } |
3042 |
3063 |
3043 allocate_dummy_regions(); |
3064 allocate_dummy_regions(); |
3044 |
3065 |
3045 _allocator->init_mutator_alloc_region(); |
3066 _allocator->init_mutator_alloc_regions(); |
3046 |
3067 |
3047 expand_heap_after_young_collection(); |
3068 expand_heap_after_young_collection(); |
3048 |
3069 |
3049 double sample_end_time_sec = os::elapsedTime(); |
3070 double sample_end_time_sec = os::elapsedTime(); |
3050 double pause_time_ms = (sample_end_time_sec - sample_start_time_sec) * MILLIUNITS; |
3071 double pause_time_ms = (sample_end_time_sec - sample_start_time_sec) * MILLIUNITS; |
4536 } |
4557 } |
4537 |
4558 |
4538 // Methods for the mutator alloc region |
4559 // Methods for the mutator alloc region |
4539 |
4560 |
4540 HeapRegion* G1CollectedHeap::new_mutator_alloc_region(size_t word_size, |
4561 HeapRegion* G1CollectedHeap::new_mutator_alloc_region(size_t word_size, |
4541 bool force) { |
4562 bool force, |
|
4563 uint node_index) { |
4542 assert_heap_locked_or_at_safepoint(true /* should_be_vm_thread */); |
4564 assert_heap_locked_or_at_safepoint(true /* should_be_vm_thread */); |
4543 bool should_allocate = policy()->should_allocate_mutator_region(); |
4565 bool should_allocate = policy()->should_allocate_mutator_region(); |
4544 if (force || should_allocate) { |
4566 if (force || should_allocate) { |
4545 HeapRegion* new_alloc_region = new_region(word_size, |
4567 HeapRegion* new_alloc_region = new_region(word_size, |
4546 HeapRegionType::Eden, |
4568 HeapRegionType::Eden, |
4547 false /* do_expand */); |
4569 false /* do_expand */, |
|
4570 node_index); |
4548 if (new_alloc_region != NULL) { |
4571 if (new_alloc_region != NULL) { |
4549 set_region_short_lived_locked(new_alloc_region); |
4572 set_region_short_lived_locked(new_alloc_region); |
4550 _hr_printer.alloc(new_alloc_region, !should_allocate); |
4573 _hr_printer.alloc(new_alloc_region, !should_allocate); |
4551 _verifier->check_bitmaps("Mutator Region Allocation", new_alloc_region); |
4574 _verifier->check_bitmaps("Mutator Region Allocation", new_alloc_region); |
4552 _policy->remset_tracker()->update_at_allocate(new_alloc_region); |
4575 _policy->remset_tracker()->update_at_allocate(new_alloc_region); |