src/share/vm/gc_implementation/parallelScavenge/psAdaptiveSizePolicy.cpp

changeset 6267
a034dc5e910b
parent 6085
8f07aa079343
child 6680
78bbf4d43a14
     1.1 --- a/src/share/vm/gc_implementation/parallelScavenge/psAdaptiveSizePolicy.cpp	Thu Jan 30 14:05:07 2014 -0800
     1.2 +++ b/src/share/vm/gc_implementation/parallelScavenge/psAdaptiveSizePolicy.cpp	Wed Jan 29 23:17:05 2014 +0100
     1.3 @@ -23,6 +23,7 @@
     1.4   */
     1.5  
     1.6  #include "precompiled.hpp"
     1.7 +#include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
     1.8  #include "gc_implementation/parallelScavenge/psAdaptiveSizePolicy.hpp"
     1.9  #include "gc_implementation/parallelScavenge/psGCAdaptivePolicyCounters.hpp"
    1.10  #include "gc_implementation/parallelScavenge/psScavenge.hpp"
    1.11 @@ -76,6 +77,38 @@
    1.12    _old_gen_policy_is_ready = false;
    1.13  }
    1.14  
    1.15 +size_t PSAdaptiveSizePolicy::calculate_free_based_on_live(size_t live, uintx ratio_as_percentage) {
    1.16 +  // We want to calculate how much free memory there can be based on the
    1.17 +  // amount of live data currently in the old gen. Using the formula:
    1.18 +  // ratio * (free + live) = free
    1.19 +  // Some equation solving later we get:
    1.20 +  // free = (live * ratio) / (1 - ratio)
    1.21 +
    1.22 +  const double ratio = ratio_as_percentage / 100.0;
    1.23 +  const double ratio_inverse = 1.0 - ratio;
    1.24 +  const double tmp = live * ratio;
    1.25 +  size_t free = (size_t)(tmp / ratio_inverse);
    1.26 +
    1.27 +  return free;
    1.28 +}
    1.29 +
    1.30 +size_t PSAdaptiveSizePolicy::calculated_old_free_size_in_bytes() const {
    1.31 +  size_t free_size = (size_t)(_promo_size + avg_promoted()->padded_average());
    1.32 +  size_t live = ParallelScavengeHeap::heap()->old_gen()->used_in_bytes();
    1.33 +
    1.34 +  if (MinHeapFreeRatio != 0) {
    1.35 +    size_t min_free = calculate_free_based_on_live(live, MinHeapFreeRatio);
    1.36 +    free_size = MAX2(free_size, min_free);
    1.37 +  }
    1.38 +
    1.39 +  if (MaxHeapFreeRatio != 100) {
    1.40 +    size_t max_free = calculate_free_based_on_live(live, MaxHeapFreeRatio);
    1.41 +    free_size = MIN2(max_free, free_size);
    1.42 +  }
    1.43 +
    1.44 +  return free_size;
    1.45 +}
    1.46 +
    1.47  void PSAdaptiveSizePolicy::major_collection_begin() {
    1.48    // Update the interval time
    1.49    _major_timer.stop();
    1.50 @@ -1292,3 +1325,18 @@
    1.51                            st,
    1.52                            PSScavenge::tenuring_threshold());
    1.53  }
    1.54 +
    1.55 +#ifndef PRODUCT
    1.56 +
    1.57 +void TestOldFreeSpaceCalculation_test() {
    1.58 +  assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(100, 20) == 25, "Calculation of free memory failed");
    1.59 +  assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(100, 50) == 100, "Calculation of free memory failed");
    1.60 +  assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(100, 60) == 150, "Calculation of free memory failed");
    1.61 +  assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(100, 75) == 300, "Calculation of free memory failed");
    1.62 +  assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(400, 20) == 100, "Calculation of free memory failed");
    1.63 +  assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(400, 50) == 400, "Calculation of free memory failed");
    1.64 +  assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(400, 60) == 600, "Calculation of free memory failed");
    1.65 +  assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(400, 75) == 1200, "Calculation of free memory failed");
    1.66 +}
    1.67 +
    1.68 +#endif /* !PRODUCT */

mercurial