comparison src/share/vm/gc_implementation/g1/heapRegion.cpp @ 942:2c79770d1f6e

6819085: G1: use larger and/or user settable region size Summary: Instead of the region size being hard-coded, allow the user to set it. Reviewed-by: jmasa, johnc, apetrusenko
author tonyp
date Thu, 30 Jul 2009 16:22:58 -0400
parents 18f526145aea
children ff2402f6a50b
comparison
equal deleted inserted replaced
941:8b46c4d82093 942:2c79770d1f6e
22 * 22 *
23 */ 23 */
24 24
25 #include "incls/_precompiled.incl" 25 #include "incls/_precompiled.incl"
26 #include "incls/_heapRegion.cpp.incl" 26 #include "incls/_heapRegion.cpp.incl"
27
28 int HeapRegion::LogOfHRGrainBytes = 0;
29 int HeapRegion::LogOfHRGrainWords = 0;
30 int HeapRegion::GrainBytes = 0;
31 int HeapRegion::GrainWords = 0;
32 int HeapRegion::CardsPerRegion = 0;
27 33
28 HeapRegionDCTOC::HeapRegionDCTOC(G1CollectedHeap* g1, 34 HeapRegionDCTOC::HeapRegionDCTOC(G1CollectedHeap* g1,
29 HeapRegion* hr, OopClosure* cl, 35 HeapRegion* hr, OopClosure* cl,
30 CardTableModRefBS::PrecisionStyle precision, 36 CardTableModRefBS::PrecisionStyle precision,
31 FilterKind fk) : 37 FilterKind fk) :
229 oop(bottom)->oop_iterate(cl2, mr); 235 oop(bottom)->oop_iterate(cl2, mr);
230 } 236 }
231 } 237 }
232 } 238 }
233 239
240 // Minimum region size; we won't go lower than that.
241 // We might want to decrease this in the future, to deal with small
242 // heaps a bit more efficiently.
243 #define MIN_REGION_SIZE ( 1024 * 1024 )
244
245 // Maximum region size; we don't go higher than that. There's a good
246 // reason for having an upper bound. We don't want regions to get too
247 // large, otherwise cleanup's effectiveness would decrease as there
248 // will be fewer opportunities to find totally empty regions after
249 // marking.
250 #define MAX_REGION_SIZE ( 32 * 1024 * 1024 )
251
252 // The automatic region size calculation will try to have around this
253 // many regions in the heap (based on the min heap size).
254 #define TARGET_REGION_NUMBER 2048
255
256 void HeapRegion::setup_heap_region_size(uintx min_heap_size) {
257 // region_size in bytes
258 uintx region_size = G1HeapRegionSize;
259 if (FLAG_IS_DEFAULT(G1HeapRegionSize)) {
260 // We base the automatic calculation on the min heap size. This
261 // can be problematic if the spread between min and max is quite
262 // wide, imagine -Xms128m -Xmx32g. But, if we decided it based on
263 // the max size, the region size might be way too large for the
264 // min size. Either way, some users might have to set the region
265 // size manually for some -Xms / -Xmx combos.
266
267 region_size = MAX2(min_heap_size / TARGET_REGION_NUMBER,
268 (uintx) MIN_REGION_SIZE);
269 }
270
271 int region_size_log = log2_long((jlong) region_size);
272 // Recalculate the region size to make sure it's a power of
273 // 2. This means that region_size is the largest power of 2 that's
274 // <= what we've calculated so far.
275 region_size = 1 << region_size_log;
276
277 // Now make sure that we don't go over or under our limits.
278 if (region_size < MIN_REGION_SIZE) {
279 region_size = MIN_REGION_SIZE;
280 } else if (region_size > MAX_REGION_SIZE) {
281 region_size = MAX_REGION_SIZE;
282 }
283
284 // And recalculate the log.
285 region_size_log = log2_long((jlong) region_size);
286
287 // Now, set up the globals.
288 guarantee(LogOfHRGrainBytes == 0, "we should only set it once");
289 LogOfHRGrainBytes = region_size_log;
290
291 guarantee(LogOfHRGrainWords == 0, "we should only set it once");
292 LogOfHRGrainWords = LogOfHRGrainBytes - LogHeapWordSize;
293
294 guarantee(GrainBytes == 0, "we should only set it once");
295 // The cast to int is safe, given that we've bounded region_size by
296 // MIN_REGION_SIZE and MAX_REGION_SIZE.
297 GrainBytes = (int) region_size;
298
299 guarantee(GrainWords == 0, "we should only set it once");
300 GrainWords = GrainBytes >> LogHeapWordSize;
301 guarantee(1 << LogOfHRGrainWords == GrainWords, "sanity");
302
303 guarantee(CardsPerRegion == 0, "we should only set it once");
304 CardsPerRegion = GrainBytes >> CardTableModRefBS::card_shift;
305 }
306
234 void HeapRegion::reset_after_compaction() { 307 void HeapRegion::reset_after_compaction() {
235 G1OffsetTableContigSpace::reset_after_compaction(); 308 G1OffsetTableContigSpace::reset_after_compaction();
236 // After a compaction the mark bitmap is invalid, so we must 309 // After a compaction the mark bitmap is invalid, so we must
237 // treat all objects as being inside the unmarked area. 310 // treat all objects as being inside the unmarked area.
238 zero_marked_bytes(); 311 zero_marked_bytes();