hotspot/src/share/vm/gc/shared/gcUtil.cpp
author dlong
Sat, 17 Oct 2015 19:40:30 -0400
changeset 33198 b37ad9fbf681
parent 30764 fec48bf5a827
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 22551
diff changeset
     2
 * Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4574
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4574
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4574
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 22551
diff changeset
    26
#include "gc/shared/gcUtil.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// Catch-all file for utility classes
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
float AdaptiveWeightedAverage::compute_adaptive_average(float new_sample,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
                                                        float average) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  // We smooth the samples by not using weight() directly until we've
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  // had enough data to make it meaningful. We'd like the first weight
12626
042841456ce1 7158457: division by zero in adaptiveweightedaverage
mikael
parents: 8921
diff changeset
    34
  // used to be 1, the second to be 1/2, etc until we have
042841456ce1 7158457: division by zero in adaptiveweightedaverage
mikael
parents: 8921
diff changeset
    35
  // OLD_THRESHOLD/weight samples.
042841456ce1 7158457: division by zero in adaptiveweightedaverage
mikael
parents: 8921
diff changeset
    36
  unsigned count_weight = 0;
042841456ce1 7158457: division by zero in adaptiveweightedaverage
mikael
parents: 8921
diff changeset
    37
042841456ce1 7158457: division by zero in adaptiveweightedaverage
mikael
parents: 8921
diff changeset
    38
  // Avoid division by zero if the counter wraps (7158457)
042841456ce1 7158457: division by zero in adaptiveweightedaverage
mikael
parents: 8921
diff changeset
    39
  if (!is_old()) {
042841456ce1 7158457: division by zero in adaptiveweightedaverage
mikael
parents: 8921
diff changeset
    40
    count_weight = OLD_THRESHOLD/count();
042841456ce1 7158457: division by zero in adaptiveweightedaverage
mikael
parents: 8921
diff changeset
    41
  }
042841456ce1 7158457: division by zero in adaptiveweightedaverage
mikael
parents: 8921
diff changeset
    42
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  unsigned adaptive_weight = (MAX2(weight(), count_weight));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  float new_avg = exp_avg(average, new_sample, adaptive_weight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  return new_avg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
void AdaptiveWeightedAverage::sample(float new_sample) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  increment_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  // Compute the new weighted average
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  float new_avg = compute_adaptive_average(new_sample, average());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  set_average(new_avg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  _last_sample = new_sample;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    59
void AdaptiveWeightedAverage::print() const {
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    60
  print_on(tty);
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    61
}
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    62
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    63
void AdaptiveWeightedAverage::print_on(outputStream* st) const {
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    64
  guarantee(false, "NYI");
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    65
}
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    66
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    67
void AdaptivePaddedAverage::print() const {
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    68
  print_on(tty);
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    69
}
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    70
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    71
void AdaptivePaddedAverage::print_on(outputStream* st) const {
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    72
  guarantee(false, "NYI");
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    73
}
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    74
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    75
void AdaptivePaddedNoZeroDevAverage::print() const {
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    76
  print_on(tty);
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    77
}
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    78
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    79
void AdaptivePaddedNoZeroDevAverage::print_on(outputStream* st) const {
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    80
  guarantee(false, "NYI");
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    81
}
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    82
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
void AdaptivePaddedAverage::sample(float new_sample) {
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    84
  // Compute new adaptive weighted average based on new sample.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  AdaptiveWeightedAverage::sample(new_sample);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    87
  // Now update the deviation and the padded average.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  float new_avg = average();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  float new_dev = compute_adaptive_average(fabsd(new_sample - new_avg),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
                                           deviation());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  set_deviation(new_dev);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  set_padded_average(new_avg + padding() * new_dev);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  _last_sample = new_sample;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
void AdaptivePaddedNoZeroDevAverage::sample(float new_sample) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  // Compute our parent classes sample information
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  AdaptiveWeightedAverage::sample(new_sample);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  float new_avg = average();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  if (new_sample != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    // We only create a new deviation if the sample is non-zero
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    float new_dev = compute_adaptive_average(fabsd(new_sample - new_avg),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
                                             deviation());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    set_deviation(new_dev);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  set_padded_average(new_avg + padding() * deviation());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  _last_sample = new_sample;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
LinearLeastSquareFit::LinearLeastSquareFit(unsigned weight) :
8104
f51b1f1750ac 7016998: gcutil class LinearLeastSquareFit doesn't initialize some of its fields
phh
parents: 7397
diff changeset
   113
  _sum_x(0), _sum_x_squared(0), _sum_y(0), _sum_xy(0),
f51b1f1750ac 7016998: gcutil class LinearLeastSquareFit doesn't initialize some of its fields
phh
parents: 7397
diff changeset
   114
  _intercept(0), _slope(0), _mean_x(weight), _mean_y(weight) {}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
void LinearLeastSquareFit::update(double x, double y) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  _sum_x = _sum_x + x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  _sum_x_squared = _sum_x_squared + x * x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  _sum_y = _sum_y + y;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  _sum_xy = _sum_xy + x * y;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  _mean_x.sample(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  _mean_y.sample(y);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  assert(_mean_x.count() == _mean_y.count(), "Incorrect count");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  if ( _mean_x.count() > 1 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    double slope_denominator;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    slope_denominator = (_mean_x.count() * _sum_x_squared - _sum_x * _sum_x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    // Some tolerance should be injected here.  A denominator that is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    // nearly 0 should be avoided.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    if (slope_denominator != 0.0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
      double slope_numerator;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
      slope_numerator = (_mean_x.count() * _sum_xy - _sum_x * _sum_y);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
      _slope = slope_numerator / slope_denominator;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
      // The _mean_y and _mean_x are decaying averages and can
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
      // be used to discount earlier data.  If they are used,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
      // first consider whether all the quantities should be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
      // kept as decaying averages.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
      // _intercept = _mean_y.average() - _slope * _mean_x.average();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
      _intercept = (_sum_y - _slope * _sum_x) / ((double) _mean_x.count());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
double LinearLeastSquareFit::y(double x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  double new_y;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  if ( _mean_x.count() > 1 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
    new_y = (_intercept + _slope * x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
    return new_y;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
    return _mean_y.average();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
// Both decrement_will_decrease() and increment_will_decrease() return
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
// true for a slope of 0.  That is because a change is necessary before
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
// a slope can be calculated and a 0 slope will, in general, indicate
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
// that no calculation of the slope has yet been done.  Returning true
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
// for a slope equal to 0 reflects the intuitive expectation of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
// dependence on the slope.  Don't use the complement of these functions
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 13963
diff changeset
   162
// since that intuitive expectation is not built into the complement.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
bool LinearLeastSquareFit::decrement_will_decrease() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  return (_slope >= 0.00);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
bool LinearLeastSquareFit::increment_will_decrease() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  return (_slope <= 0.00);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
}