110 ShenandoahHeuristics::ShenandoahHeuristics() :
111 _bytes_allocated_since_CM(0),
112 _bytes_reclaimed_this_cycle(0),
113 _bytes_allocated_start_CM(0),
114 _bytes_allocated_during_CM(0),
115 _garbage_threshold(ShenandoahHeapRegion::RegionSizeBytes / 2)
116 {
117 if (ShenandoahPrintGCDetails)
118 tty->print_cr("initializing heuristics");
119 }
120
121 void ShenandoahHeuristics::choose_collection_set(ShenandoahCollectionSet* collection_set) {
122 ShenandoahHeapRegionSet* sorted_regions = ShenandoahHeap::heap()->sorted_regions();
123 sorted_regions->sort(compareHeapRegionsByGarbage);
124
125 jlong i = 0;
126 jlong end = sorted_regions->active_regions();
127
128 while (i < end) {
129 ShenandoahHeapRegion* region = sorted_regions->get(i++);
130 if (region->garbage() > _garbage_threshold && ! region->is_humongous()) {
131 // tty->print("choose region %d with garbage = " SIZE_FORMAT " and live = " SIZE_FORMAT " and _garbage_threshold = " SIZE_FORMAT "\n",
132 // region->region_number(), region->garbage(), region->getLiveData(), _garbage_threshold);
133
134 assert(! region->is_humongous(), "no humongous regions in collection set");
135
136 if (region->getLiveData() == 0) {
137 // We can recycle it right away and put it in the free set.
138 ShenandoahHeap::heap()->decrease_used(region->used());
139 region->recycle();
140 } else {
141 collection_set->add_region(region);
142 region->set_is_in_collection_set(true);
143 }
144 // } else {
145 // tty->print("rejected region %d with garbage = " SIZE_FORMAT " and live = " SIZE_FORMAT " and _garbage_threshold = " SIZE_FORMAT "\n",
146 // region->region_number(), region->garbage(), region->getLiveData(), _garbage_threshold);
147 }
148 }
149
150 }
151
152 void ShenandoahHeuristics::choose_collection_set_min_garbage(ShenandoahCollectionSet* collection_set, size_t min_garbage) {
153 ShenandoahHeapRegionSet* sorted_regions = ShenandoahHeap::heap()->sorted_regions();
154 sorted_regions->sort(compareHeapRegionsByGarbage);
155 jlong i = 0;
156 jlong end = sorted_regions->active_regions();
157
158 size_t garbage = 0;
159 while (i < end && garbage < min_garbage) {
160 ShenandoahHeapRegion* region = sorted_regions->get(i++);
161 if (region->garbage() > _garbage_threshold && ! region->is_humongous()) {
162 collection_set->add_region(region);
163 garbage += region->garbage();
164 region->set_is_in_collection_set(true);
165 }
166 }
167 }
168
169 void ShenandoahHeuristics::choose_free_set(ShenandoahFreeSet* free_set) {
170
171 ShenandoahHeapRegionSet* ordered_regions = ShenandoahHeap::heap()->regions();
172 jlong i = 0;
173 jlong end = ordered_regions->active_regions();
174
175 while (i < end) {
176 ShenandoahHeapRegion* region = ordered_regions->get(i++);
177 if ((! region->is_in_collection_set())
178 && (! region->is_humongous())) {
179 free_set->add_region(region);
180 }
181 }
182 }
183
184 void ShenandoahCollectorPolicy::record_workers_start(TimingPhase phase) {
185 for (uint i = 0; i < ShenandoahPhaseTimes::GCParPhasesSentinel; i++) {
186 _phase_times->reset(i);
187 }
188 }
189
190 void ShenandoahCollectorPolicy::record_workers_end(TimingPhase phase) {
191 if (phase != _num_phases) {
192 for (uint i = 0; i < ShenandoahPhaseTimes::GCParPhasesSentinel; i++) {
193 double t = _phase_times->average(i);
194 _timing_data[phase + i]._ms.add(t * 1000.0);
195 }
196 }
197 }
198
|
110 ShenandoahHeuristics::ShenandoahHeuristics() :
111 _bytes_allocated_since_CM(0),
112 _bytes_reclaimed_this_cycle(0),
113 _bytes_allocated_start_CM(0),
114 _bytes_allocated_during_CM(0),
115 _garbage_threshold(ShenandoahHeapRegion::RegionSizeBytes / 2)
116 {
117 if (ShenandoahPrintGCDetails)
118 tty->print_cr("initializing heuristics");
119 }
120
121 void ShenandoahHeuristics::choose_collection_set(ShenandoahCollectionSet* collection_set) {
122 ShenandoahHeapRegionSet* sorted_regions = ShenandoahHeap::heap()->sorted_regions();
123 sorted_regions->sort(compareHeapRegionsByGarbage);
124
125 jlong i = 0;
126 jlong end = sorted_regions->active_regions();
127
128 while (i < end) {
129 ShenandoahHeapRegion* region = sorted_regions->get(i++);
130 if (region->garbage() > _garbage_threshold && ! region->is_humongous() && ! region->is_pinned()) {
131 // tty->print("choose region %d with garbage = " SIZE_FORMAT " and live = " SIZE_FORMAT " and _garbage_threshold = " SIZE_FORMAT "\n",
132 // region->region_number(), region->garbage(), region->getLiveData(), _garbage_threshold);
133
134 assert(! region->is_humongous(), "no humongous regions in collection set");
135
136 if (region->getLiveData() == 0) {
137 // We can recycle it right away and put it in the free set.
138 ShenandoahHeap::heap()->decrease_used(region->used());
139 region->recycle();
140 } else {
141 collection_set->add_region(region);
142 region->set_is_in_collection_set(true);
143 }
144 // } else {
145 // tty->print("rejected region %d with garbage = " SIZE_FORMAT " and live = " SIZE_FORMAT " and _garbage_threshold = " SIZE_FORMAT "\n",
146 // region->region_number(), region->garbage(), region->getLiveData(), _garbage_threshold);
147 }
148 }
149
150 }
151
152 void ShenandoahHeuristics::choose_collection_set_min_garbage(ShenandoahCollectionSet* collection_set, size_t min_garbage) {
153 ShenandoahHeapRegionSet* sorted_regions = ShenandoahHeap::heap()->sorted_regions();
154 sorted_regions->sort(compareHeapRegionsByGarbage);
155 jlong i = 0;
156 jlong end = sorted_regions->active_regions();
157
158 size_t garbage = 0;
159 while (i < end && garbage < min_garbage) {
160 ShenandoahHeapRegion* region = sorted_regions->get(i++);
161 if (region->garbage() > _garbage_threshold && ! region->is_humongous() && ! region->is_pinned()) {
162 collection_set->add_region(region);
163 garbage += region->garbage();
164 region->set_is_in_collection_set(true);
165 }
166 }
167 }
168
169 void ShenandoahHeuristics::choose_free_set(ShenandoahFreeSet* free_set) {
170
171 ShenandoahHeapRegionSet* ordered_regions = ShenandoahHeap::heap()->regions();
172 jlong i = 0;
173 jlong end = ordered_regions->active_regions();
174
175 while (i < end) {
176 ShenandoahHeapRegion* region = ordered_regions->get(i++);
177 if ((! region->is_in_collection_set())
178 && (! region->is_humongous())
179 && (! region->is_pinned())) {
180 free_set->add_region(region);
181 }
182 }
183 }
184
185 void ShenandoahCollectorPolicy::record_workers_start(TimingPhase phase) {
186 for (uint i = 0; i < ShenandoahPhaseTimes::GCParPhasesSentinel; i++) {
187 _phase_times->reset(i);
188 }
189 }
190
191 void ShenandoahCollectorPolicy::record_workers_end(TimingPhase phase) {
192 if (phase != _num_phases) {
193 for (uint i = 0; i < ShenandoahPhaseTimes::GCParPhasesSentinel; i++) {
194 double t = _phase_times->average(i);
195 _timing_data[phase + i]._ms.add(t * 1000.0);
196 }
197 }
198 }
199
|