Mercurial > hg > graal-jvmci-8
comparison src/share/vm/gc_implementation/parallelScavenge/psAdaptiveSizePolicy.cpp @ 1387:0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
Summary: Ensure a full GC that clears SoftReferences before throwing an out-of-memory
Reviewed-by: ysr, jcoomes
author | jmasa |
---|---|
date | Tue, 13 Apr 2010 13:52:10 -0700 |
parents | a61af66fc99e |
children | c18cbe5936b8 |
comparison
equal
deleted
inserted
replaced
1361:6b73e879f1c2 | 1387:0bfd3fb24150 |
---|---|
1 /* | 1 /* |
2 * Copyright 2002-2007 Sun Microsystems, Inc. All Rights Reserved. | 2 * Copyright 2002-2010 Sun Microsystems, Inc. All Rights Reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
182 set_change_old_gen_for_min_pauses(0); | 182 set_change_old_gen_for_min_pauses(0); |
183 | 183 |
184 set_change_young_gen_for_maj_pauses(0); | 184 set_change_young_gen_for_maj_pauses(0); |
185 } | 185 } |
186 | 186 |
187 | |
188 // If this is not a full GC, only test and modify the young generation. | 187 // If this is not a full GC, only test and modify the young generation. |
189 | 188 |
190 void PSAdaptiveSizePolicy::compute_generation_free_space(size_t young_live, | 189 void PSAdaptiveSizePolicy::compute_generation_free_space( |
191 size_t eden_live, | 190 size_t young_live, |
192 size_t old_live, | 191 size_t eden_live, |
193 size_t perm_live, | 192 size_t old_live, |
194 size_t cur_eden, | 193 size_t perm_live, |
195 size_t max_old_gen_size, | 194 size_t cur_eden, |
196 size_t max_eden_size, | 195 size_t max_old_gen_size, |
197 bool is_full_gc, | 196 size_t max_eden_size, |
198 GCCause::Cause gc_cause) { | 197 bool is_full_gc, |
198 GCCause::Cause gc_cause, | |
199 CollectorPolicy* collector_policy) { | |
199 | 200 |
200 // Update statistics | 201 // Update statistics |
201 // Time statistics are updated as we go, update footprint stats here | 202 // Time statistics are updated as we go, update footprint stats here |
202 _avg_base_footprint->sample(BaseFootPrintEstimate + perm_live); | 203 _avg_base_footprint->sample(BaseFootPrintEstimate + perm_live); |
203 avg_young_live()->sample(young_live); | 204 avg_young_live()->sample(young_live); |
378 promo_limit = align_size_down(promo_limit, alignment); | 379 promo_limit = align_size_down(promo_limit, alignment); |
379 | 380 |
380 // Is too much time being spent in GC? | 381 // Is too much time being spent in GC? |
381 // Is the heap trying to grow beyond it's limits? | 382 // Is the heap trying to grow beyond it's limits? |
382 | 383 |
383 const size_t free_in_old_gen = (size_t)(max_old_gen_size - avg_old_live()->average()); | 384 const size_t free_in_old_gen = |
385 (size_t)(max_old_gen_size - avg_old_live()->average()); | |
384 if (desired_promo_size > free_in_old_gen && desired_eden_size > eden_limit) { | 386 if (desired_promo_size > free_in_old_gen && desired_eden_size > eden_limit) { |
385 | 387 check_gc_overhead_limit(young_live, |
386 // eden_limit is the upper limit on the size of eden based on | 388 eden_live, |
387 // the maximum size of the young generation and the sizes | 389 max_old_gen_size, |
388 // of the survivor space. | 390 max_eden_size, |
389 // The question being asked is whether the gc costs are high | 391 is_full_gc, |
390 // and the space being recovered by a collection is low. | 392 gc_cause, |
391 // free_in_young_gen is the free space in the young generation | 393 collector_policy); |
392 // after a collection and promo_live is the free space in the old | |
393 // generation after a collection. | |
394 // | |
395 // Use the minimum of the current value of the live in the | |
396 // young gen or the average of the live in the young gen. | |
397 // If the current value drops quickly, that should be taken | |
398 // into account (i.e., don't trigger if the amount of free | |
399 // space has suddenly jumped up). If the current is much | |
400 // higher than the average, use the average since it represents | |
401 // the longer term behavor. | |
402 const size_t live_in_eden = MIN2(eden_live, (size_t) avg_eden_live()->average()); | |
403 const size_t free_in_eden = eden_limit > live_in_eden ? | |
404 eden_limit - live_in_eden : 0; | |
405 const size_t total_free_limit = free_in_old_gen + free_in_eden; | |
406 const size_t total_mem = max_old_gen_size + max_eden_size; | |
407 const double mem_free_limit = total_mem * (GCHeapFreeLimit/100.0); | |
408 if (PrintAdaptiveSizePolicy && (Verbose || | |
409 (total_free_limit < (size_t) mem_free_limit))) { | |
410 gclog_or_tty->print_cr( | |
411 "PSAdaptiveSizePolicy::compute_generation_free_space limits:" | |
412 " promo_limit: " SIZE_FORMAT | |
413 " eden_limit: " SIZE_FORMAT | |
414 " total_free_limit: " SIZE_FORMAT | |
415 " max_old_gen_size: " SIZE_FORMAT | |
416 " max_eden_size: " SIZE_FORMAT | |
417 " mem_free_limit: " SIZE_FORMAT, | |
418 promo_limit, eden_limit, total_free_limit, | |
419 max_old_gen_size, max_eden_size, | |
420 (size_t) mem_free_limit); | |
421 } | |
422 | |
423 if (is_full_gc) { | |
424 if (gc_cost() > gc_cost_limit && | |
425 total_free_limit < (size_t) mem_free_limit) { | |
426 // Collections, on average, are taking too much time, and | |
427 // gc_cost() > gc_cost_limit | |
428 // we have too little space available after a full gc. | |
429 // total_free_limit < mem_free_limit | |
430 // where | |
431 // total_free_limit is the free space available in | |
432 // both generations | |
433 // total_mem is the total space available for allocation | |
434 // in both generations (survivor spaces are not included | |
435 // just as they are not included in eden_limit). | |
436 // mem_free_limit is a fraction of total_mem judged to be an | |
437 // acceptable amount that is still unused. | |
438 // The heap can ask for the value of this variable when deciding | |
439 // whether to thrown an OutOfMemory error. | |
440 // Note that the gc time limit test only works for the collections | |
441 // of the young gen + tenured gen and not for collections of the | |
442 // permanent gen. That is because the calculation of the space | |
443 // freed by the collection is the free space in the young gen + | |
444 // tenured gen. | |
445 // Ignore explicit GC's. Ignoring explicit GC's at this level | |
446 // is the equivalent of the GC did not happen as far as the | |
447 // overhead calculation is concerted (i.e., the flag is not set | |
448 // and the count is not affected). Also the average will not | |
449 // have been updated unless UseAdaptiveSizePolicyWithSystemGC is on. | |
450 if (!GCCause::is_user_requested_gc(gc_cause) && | |
451 !GCCause::is_serviceability_requested_gc(gc_cause)) { | |
452 inc_gc_time_limit_count(); | |
453 if (UseGCOverheadLimit && | |
454 (gc_time_limit_count() > AdaptiveSizePolicyGCTimeLimitThreshold)){ | |
455 // All conditions have been met for throwing an out-of-memory | |
456 _gc_time_limit_exceeded = true; | |
457 // Avoid consecutive OOM due to the gc time limit by resetting | |
458 // the counter. | |
459 reset_gc_time_limit_count(); | |
460 } | |
461 _print_gc_time_limit_would_be_exceeded = true; | |
462 } | |
463 } else { | |
464 // Did not exceed overhead limits | |
465 reset_gc_time_limit_count(); | |
466 } | |
467 } | |
468 } | 394 } |
469 | 395 |
470 | 396 |
471 // And one last limit check, now that we've aligned things. | 397 // And one last limit check, now that we've aligned things. |
472 if (desired_eden_size > eden_limit) { | 398 if (desired_eden_size > eden_limit) { |