comparison src/share/vm/gc_implementation/g1/collectionSetChooser.cpp @ 4095:bca17e38de00

6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads Summary: Select number of GC threads dynamically based on heap usage and number of Java threads Reviewed-by: johnc, ysr, jcoomes
author jmasa
date Tue, 09 Aug 2011 10:16:01 -0700
parents b9390528617c
children 441e946dc1af
comparison
equal deleted inserted replaced
4094:3a298e04d914 4095:bca17e38de00
253 253
254 void 254 void
255 CollectionSetChooser:: 255 CollectionSetChooser::
256 prepareForAddMarkedHeapRegionsPar(size_t n_regions, size_t chunkSize) { 256 prepareForAddMarkedHeapRegionsPar(size_t n_regions, size_t chunkSize) {
257 _first_par_unreserved_idx = 0; 257 _first_par_unreserved_idx = 0;
258 size_t max_waste = ParallelGCThreads * chunkSize; 258 int n_threads = ParallelGCThreads;
259 if (UseDynamicNumberOfGCThreads) {
260 assert(G1CollectedHeap::heap()->workers()->active_workers() > 0,
261 "Should have been set earlier");
262 // This is defensive code. As the assertion above says, the number
263 // of active threads should be > 0, but in case there is some path
264 // or some improperly initialized variable with leads to no
265 // active threads, protect against that in a product build.
266 n_threads = MAX2(G1CollectedHeap::heap()->workers()->active_workers(),
267 1);
268 }
269 size_t max_waste = n_threads * chunkSize;
259 // it should be aligned with respect to chunkSize 270 // it should be aligned with respect to chunkSize
260 size_t aligned_n_regions = 271 size_t aligned_n_regions =
261 (n_regions + (chunkSize - 1)) / chunkSize * chunkSize; 272 (n_regions + (chunkSize - 1)) / chunkSize * chunkSize;
262 assert( aligned_n_regions % chunkSize == 0, "should be aligned" ); 273 assert( aligned_n_regions % chunkSize == 0, "should be aligned" );
263 _markedRegions.at_put_grow((int)(aligned_n_regions + max_waste - 1), NULL); 274 _markedRegions.at_put_grow((int)(aligned_n_regions + max_waste - 1), NULL);
264 } 275 }
265 276
266 jint 277 jint
267 CollectionSetChooser::getParMarkedHeapRegionChunk(jint n_regions) { 278 CollectionSetChooser::getParMarkedHeapRegionChunk(jint n_regions) {
279 // Don't do this assert because this can be called at a point
280 // where the loop up stream will not execute again but might
281 // try to claim more chunks (loop test has not been done yet).
282 // assert(_markedRegions.length() > _first_par_unreserved_idx,
283 // "Striding beyond the marked regions");
268 jint res = Atomic::add(n_regions, &_first_par_unreserved_idx); 284 jint res = Atomic::add(n_regions, &_first_par_unreserved_idx);
269 assert(_markedRegions.length() > res + n_regions - 1, 285 assert(_markedRegions.length() > res + n_regions - 1,
270 "Should already have been expanded"); 286 "Should already have been expanded");
271 return res - n_regions; 287 return res - n_regions;
272 } 288 }