74 // The first argument, however, is actually a comma expression 75 // (set_allocation_type(this, C_HEAP), 100). The purpose of the 76 // set_allocation_type() call is to replace the default allocation 77 // type for embedded objects STACK_OR_EMBEDDED with C_HEAP. It will 78 // allow to pass the assert in GenericGrowableArray() which checks 79 // that a growable array object must be on C heap if elements are. 80 // 81 // Note: containing object is allocated on C heap since it is CHeapObj. 82 // 83 _regions((ResourceObj::set_allocation_type((address) &_regions, 84 ResourceObj::C_HEAP), 85 100), true /* C_Heap */), 86 _front(0), _end(0), _first_par_unreserved_idx(0), 87 _region_live_threshold_bytes(0), _remaining_reclaimable_bytes(0) { 88 _region_live_threshold_bytes = 89 HeapRegion::GrainBytes * (size_t) G1MixedGCLiveThresholdPercent / 100; 90 } 91 92 #ifndef PRODUCT 93 void CollectionSetChooser::verify() { 94 guarantee(_end <= regions_length(), 95 err_msg("_end: %u regions length: %u", _end, regions_length())); 96 guarantee(_front <= _end, 97 err_msg("_front: %u _end: %u", _front, _end)); 98 uint index = 0; 99 size_t sum_of_reclaimable_bytes = 0; 100 while (index < _front) { 101 guarantee(regions_at(index) == NULL, 102 "all entries before _front should be NULL"); 103 index += 1; 104 } 105 HeapRegion *prev = NULL; 106 while (index < _end) { 107 HeapRegion *curr = regions_at(index++); 108 guarantee(curr != NULL, "Regions in _regions array cannot be NULL"); 109 guarantee(!curr->is_young(), "should not be young!"); 110 guarantee(!curr->is_pinned(), 111 err_msg("Pinned region should not be in collection set (index %u)", curr->hrm_index())); 112 if (prev != NULL) { 113 guarantee(order_regions(prev, curr) != 1, 114 err_msg("GC eff prev: %1.4f GC eff curr: %1.4f", 115 prev->gc_efficiency(), curr->gc_efficiency())); 116 } 117 sum_of_reclaimable_bytes += curr->reclaimable_bytes(); 118 prev = curr; 119 } 120 guarantee(sum_of_reclaimable_bytes == _remaining_reclaimable_bytes, 121 err_msg("reclaimable bytes inconsistent, " 122 "remaining: " SIZE_FORMAT " sum: " SIZE_FORMAT, 123 _remaining_reclaimable_bytes, sum_of_reclaimable_bytes)); 124 } 125 #endif // !PRODUCT 126 127 void CollectionSetChooser::sort_regions() { 128 // First trim any unused portion of the top in the parallel case. 129 if (_first_par_unreserved_idx > 0) { 130 assert(_first_par_unreserved_idx <= regions_length(), 131 "Or we didn't reserved enough length"); 132 regions_trunc_to(_first_par_unreserved_idx); 133 } 134 _regions.sort(order_regions); 135 assert(_end <= regions_length(), "Requirement"); 136 #ifdef ASSERT 137 for (uint i = 0; i < _end; i++) { 138 assert(regions_at(i) != NULL, "Should be true by sorting!"); 139 } 140 #endif // ASSERT 141 if (G1PrintRegionLivenessInfo) { 142 G1PrintRegionLivenessInfoClosure cl(gclog_or_tty, "Post-Sorting"); 143 for (uint i = 0; i < _end; ++i) { 144 HeapRegion* r = regions_at(i); 145 cl.doHeapRegion(r); 146 } 147 } 148 verify(); 149 } 150 151 152 void CollectionSetChooser::add_region(HeapRegion* hr) { 153 assert(!hr->is_pinned(), 154 err_msg("Pinned region shouldn't be added to the collection set (index %u)", hr->hrm_index())); 155 assert(!hr->is_young(), "should not be young!"); 156 _regions.append(hr); 157 _end++; 158 _remaining_reclaimable_bytes += hr->reclaimable_bytes(); 159 hr->calc_gc_efficiency(); 160 } 161 162 void CollectionSetChooser::push(HeapRegion* hr) { 163 assert(hr != NULL, "Can't put back a NULL region"); 164 assert(_front >= 1, "Too many regions have been put back"); 165 _front--; 166 regions_at_put(_front, hr); 167 _remaining_reclaimable_bytes += hr->reclaimable_bytes(); 168 } 169 170 void CollectionSetChooser::prepare_for_par_region_addition(uint n_threads, 171 uint n_regions, 172 uint chunk_size) { 173 _first_par_unreserved_idx = 0; 174 uint max_waste = n_threads * chunk_size; | 74 // The first argument, however, is actually a comma expression 75 // (set_allocation_type(this, C_HEAP), 100). The purpose of the 76 // set_allocation_type() call is to replace the default allocation 77 // type for embedded objects STACK_OR_EMBEDDED with C_HEAP. It will 78 // allow to pass the assert in GenericGrowableArray() which checks 79 // that a growable array object must be on C heap if elements are. 80 // 81 // Note: containing object is allocated on C heap since it is CHeapObj. 82 // 83 _regions((ResourceObj::set_allocation_type((address) &_regions, 84 ResourceObj::C_HEAP), 85 100), true /* C_Heap */), 86 _front(0), _end(0), _first_par_unreserved_idx(0), 87 _region_live_threshold_bytes(0), _remaining_reclaimable_bytes(0) { 88 _region_live_threshold_bytes = 89 HeapRegion::GrainBytes * (size_t) G1MixedGCLiveThresholdPercent / 100; 90 } 91 92 #ifndef PRODUCT 93 void CollectionSetChooser::verify() { 94 guarantee(_end <= regions_length(), "_end: %u regions length: %u", _end, regions_length()); 95 guarantee(_front <= _end, "_front: %u _end: %u", _front, _end); 96 uint index = 0; 97 size_t sum_of_reclaimable_bytes = 0; 98 while (index < _front) { 99 guarantee(regions_at(index) == NULL, 100 "all entries before _front should be NULL"); 101 index += 1; 102 } 103 HeapRegion *prev = NULL; 104 while (index < _end) { 105 HeapRegion *curr = regions_at(index++); 106 guarantee(curr != NULL, "Regions in _regions array cannot be NULL"); 107 guarantee(!curr->is_young(), "should not be young!"); 108 guarantee(!curr->is_pinned(), 109 "Pinned region should not be in collection set (index %u)", curr->hrm_index()); 110 if (prev != NULL) { 111 guarantee(order_regions(prev, curr) != 1, 112 "GC eff prev: %1.4f GC eff curr: %1.4f", 113 prev->gc_efficiency(), curr->gc_efficiency()); 114 } 115 sum_of_reclaimable_bytes += curr->reclaimable_bytes(); 116 prev = curr; 117 } 118 guarantee(sum_of_reclaimable_bytes == _remaining_reclaimable_bytes, 119 "reclaimable bytes inconsistent, " 120 "remaining: " SIZE_FORMAT " sum: " SIZE_FORMAT, 121 _remaining_reclaimable_bytes, sum_of_reclaimable_bytes); 122 } 123 #endif // !PRODUCT 124 125 void CollectionSetChooser::sort_regions() { 126 // First trim any unused portion of the top in the parallel case. 127 if (_first_par_unreserved_idx > 0) { 128 assert(_first_par_unreserved_idx <= regions_length(), 129 "Or we didn't reserved enough length"); 130 regions_trunc_to(_first_par_unreserved_idx); 131 } 132 _regions.sort(order_regions); 133 assert(_end <= regions_length(), "Requirement"); 134 #ifdef ASSERT 135 for (uint i = 0; i < _end; i++) { 136 assert(regions_at(i) != NULL, "Should be true by sorting!"); 137 } 138 #endif // ASSERT 139 if (G1PrintRegionLivenessInfo) { 140 G1PrintRegionLivenessInfoClosure cl(gclog_or_tty, "Post-Sorting"); 141 for (uint i = 0; i < _end; ++i) { 142 HeapRegion* r = regions_at(i); 143 cl.doHeapRegion(r); 144 } 145 } 146 verify(); 147 } 148 149 150 void CollectionSetChooser::add_region(HeapRegion* hr) { 151 assert(!hr->is_pinned(), 152 "Pinned region shouldn't be added to the collection set (index %u)", hr->hrm_index()); 153 assert(!hr->is_young(), "should not be young!"); 154 _regions.append(hr); 155 _end++; 156 _remaining_reclaimable_bytes += hr->reclaimable_bytes(); 157 hr->calc_gc_efficiency(); 158 } 159 160 void CollectionSetChooser::push(HeapRegion* hr) { 161 assert(hr != NULL, "Can't put back a NULL region"); 162 assert(_front >= 1, "Too many regions have been put back"); 163 _front--; 164 regions_at_put(_front, hr); 165 _remaining_reclaimable_bytes += hr->reclaimable_bytes(); 166 } 167 168 void CollectionSetChooser::prepare_for_par_region_addition(uint n_threads, 169 uint n_regions, 170 uint chunk_size) { 171 _first_par_unreserved_idx = 0; 172 uint max_waste = n_threads * chunk_size; |