Tue, 05 Apr 2011 14:12:31 -0700
7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
Summary: Update the copyright to be 2010 on all changed files in OpenJDK
Reviewed-by: ohair
duke@435 | 1 | /* |
stefank@2314 | 2 | * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #ifndef SHARE_VM_GC_IMPLEMENTATION_SHARED_GCUTIL_HPP |
stefank@2314 | 26 | #define SHARE_VM_GC_IMPLEMENTATION_SHARED_GCUTIL_HPP |
stefank@2314 | 27 | |
stefank@2314 | 28 | #include "memory/allocation.hpp" |
stefank@2314 | 29 | #include "runtime/timer.hpp" |
stefank@2314 | 30 | #include "utilities/debug.hpp" |
stefank@2314 | 31 | #include "utilities/globalDefinitions.hpp" |
stefank@2314 | 32 | #include "utilities/ostream.hpp" |
stefank@2314 | 33 | |
duke@435 | 34 | // Catch-all file for utility classes |
duke@435 | 35 | |
duke@435 | 36 | // A weighted average maintains a running, weighted average |
duke@435 | 37 | // of some float value (templates would be handy here if we |
duke@435 | 38 | // need different types). |
duke@435 | 39 | // |
duke@435 | 40 | // The average is adaptive in that we smooth it for the |
duke@435 | 41 | // initial samples; we don't use the weight until we have |
duke@435 | 42 | // enough samples for it to be meaningful. |
duke@435 | 43 | // |
duke@435 | 44 | // This serves as our best estimate of a future unknown. |
duke@435 | 45 | // |
duke@435 | 46 | class AdaptiveWeightedAverage : public CHeapObj { |
duke@435 | 47 | private: |
duke@435 | 48 | float _average; // The last computed average |
duke@435 | 49 | unsigned _sample_count; // How often we've sampled this average |
duke@435 | 50 | unsigned _weight; // The weight used to smooth the averages |
duke@435 | 51 | // A higher weight favors the most |
duke@435 | 52 | // recent data. |
duke@435 | 53 | |
duke@435 | 54 | protected: |
duke@435 | 55 | float _last_sample; // The last value sampled. |
duke@435 | 56 | |
duke@435 | 57 | void increment_count() { _sample_count++; } |
duke@435 | 58 | void set_average(float avg) { _average = avg; } |
duke@435 | 59 | |
duke@435 | 60 | // Helper function, computes an adaptive weighted average |
duke@435 | 61 | // given a sample and the last average |
duke@435 | 62 | float compute_adaptive_average(float new_sample, float average); |
duke@435 | 63 | |
duke@435 | 64 | public: |
duke@435 | 65 | // Input weight must be between 0 and 100 |
ysr@1580 | 66 | AdaptiveWeightedAverage(unsigned weight, float avg = 0.0) : |
ysr@1580 | 67 | _average(avg), _sample_count(0), _weight(weight), _last_sample(0.0) { |
duke@435 | 68 | } |
duke@435 | 69 | |
iveresov@703 | 70 | void clear() { |
iveresov@703 | 71 | _average = 0; |
iveresov@703 | 72 | _sample_count = 0; |
iveresov@703 | 73 | _last_sample = 0; |
iveresov@703 | 74 | } |
iveresov@703 | 75 | |
ysr@1580 | 76 | // Useful for modifying static structures after startup. |
ysr@1580 | 77 | void modify(size_t avg, unsigned wt, bool force = false) { |
ysr@1580 | 78 | assert(force, "Are you sure you want to call this?"); |
ysr@1580 | 79 | _average = (float)avg; |
ysr@1580 | 80 | _weight = wt; |
ysr@1580 | 81 | } |
ysr@1580 | 82 | |
duke@435 | 83 | // Accessors |
duke@435 | 84 | float average() const { return _average; } |
duke@435 | 85 | unsigned weight() const { return _weight; } |
duke@435 | 86 | unsigned count() const { return _sample_count; } |
duke@435 | 87 | float last_sample() const { return _last_sample; } |
duke@435 | 88 | |
duke@435 | 89 | // Update data with a new sample. |
duke@435 | 90 | void sample(float new_sample); |
duke@435 | 91 | |
duke@435 | 92 | static inline float exp_avg(float avg, float sample, |
duke@435 | 93 | unsigned int weight) { |
duke@435 | 94 | assert(0 <= weight && weight <= 100, "weight must be a percent"); |
duke@435 | 95 | return (100.0F - weight) * avg / 100.0F + weight * sample / 100.0F; |
duke@435 | 96 | } |
duke@435 | 97 | static inline size_t exp_avg(size_t avg, size_t sample, |
duke@435 | 98 | unsigned int weight) { |
duke@435 | 99 | // Convert to float and back to avoid integer overflow. |
duke@435 | 100 | return (size_t)exp_avg((float)avg, (float)sample, weight); |
duke@435 | 101 | } |
ysr@1580 | 102 | |
ysr@1580 | 103 | // Printing |
ysr@1580 | 104 | void print_on(outputStream* st) const; |
ysr@1580 | 105 | void print() const; |
duke@435 | 106 | }; |
duke@435 | 107 | |
duke@435 | 108 | |
duke@435 | 109 | // A weighted average that includes a deviation from the average, |
duke@435 | 110 | // some multiple of which is added to the average. |
duke@435 | 111 | // |
duke@435 | 112 | // This serves as our best estimate of an upper bound on a future |
duke@435 | 113 | // unknown. |
duke@435 | 114 | class AdaptivePaddedAverage : public AdaptiveWeightedAverage { |
duke@435 | 115 | private: |
duke@435 | 116 | float _padded_avg; // The last computed padded average |
duke@435 | 117 | float _deviation; // Running deviation from the average |
duke@435 | 118 | unsigned _padding; // A multiple which, added to the average, |
duke@435 | 119 | // gives us an upper bound guess. |
duke@435 | 120 | |
duke@435 | 121 | protected: |
duke@435 | 122 | void set_padded_average(float avg) { _padded_avg = avg; } |
duke@435 | 123 | void set_deviation(float dev) { _deviation = dev; } |
duke@435 | 124 | |
duke@435 | 125 | public: |
duke@435 | 126 | AdaptivePaddedAverage() : |
duke@435 | 127 | AdaptiveWeightedAverage(0), |
duke@435 | 128 | _padded_avg(0.0), _deviation(0.0), _padding(0) {} |
duke@435 | 129 | |
duke@435 | 130 | AdaptivePaddedAverage(unsigned weight, unsigned padding) : |
duke@435 | 131 | AdaptiveWeightedAverage(weight), |
duke@435 | 132 | _padded_avg(0.0), _deviation(0.0), _padding(padding) {} |
duke@435 | 133 | |
duke@435 | 134 | // Placement support |
duke@435 | 135 | void* operator new(size_t ignored, void* p) { return p; } |
duke@435 | 136 | // Allocator |
duke@435 | 137 | void* operator new(size_t size) { return CHeapObj::operator new(size); } |
duke@435 | 138 | |
duke@435 | 139 | // Accessor |
duke@435 | 140 | float padded_average() const { return _padded_avg; } |
duke@435 | 141 | float deviation() const { return _deviation; } |
duke@435 | 142 | unsigned padding() const { return _padding; } |
duke@435 | 143 | |
iveresov@703 | 144 | void clear() { |
iveresov@703 | 145 | AdaptiveWeightedAverage::clear(); |
iveresov@703 | 146 | _padded_avg = 0; |
iveresov@703 | 147 | _deviation = 0; |
iveresov@703 | 148 | } |
iveresov@703 | 149 | |
duke@435 | 150 | // Override |
duke@435 | 151 | void sample(float new_sample); |
ysr@1580 | 152 | |
ysr@1580 | 153 | // Printing |
ysr@1580 | 154 | void print_on(outputStream* st) const; |
ysr@1580 | 155 | void print() const; |
duke@435 | 156 | }; |
duke@435 | 157 | |
duke@435 | 158 | // A weighted average that includes a deviation from the average, |
duke@435 | 159 | // some multiple of which is added to the average. |
duke@435 | 160 | // |
duke@435 | 161 | // This serves as our best estimate of an upper bound on a future |
duke@435 | 162 | // unknown. |
duke@435 | 163 | // A special sort of padded average: it doesn't update deviations |
duke@435 | 164 | // if the sample is zero. The average is allowed to change. We're |
duke@435 | 165 | // preventing the zero samples from drastically changing our padded |
duke@435 | 166 | // average. |
duke@435 | 167 | class AdaptivePaddedNoZeroDevAverage : public AdaptivePaddedAverage { |
duke@435 | 168 | public: |
duke@435 | 169 | AdaptivePaddedNoZeroDevAverage(unsigned weight, unsigned padding) : |
duke@435 | 170 | AdaptivePaddedAverage(weight, padding) {} |
duke@435 | 171 | // Override |
duke@435 | 172 | void sample(float new_sample); |
ysr@1580 | 173 | |
ysr@1580 | 174 | // Printing |
ysr@1580 | 175 | void print_on(outputStream* st) const; |
ysr@1580 | 176 | void print() const; |
duke@435 | 177 | }; |
ysr@1580 | 178 | |
duke@435 | 179 | // Use a least squares fit to a set of data to generate a linear |
duke@435 | 180 | // equation. |
duke@435 | 181 | // y = intercept + slope * x |
duke@435 | 182 | |
duke@435 | 183 | class LinearLeastSquareFit : public CHeapObj { |
duke@435 | 184 | double _sum_x; // sum of all independent data points x |
duke@435 | 185 | double _sum_x_squared; // sum of all independent data points x**2 |
duke@435 | 186 | double _sum_y; // sum of all dependent data points y |
duke@435 | 187 | double _sum_xy; // sum of all x * y. |
duke@435 | 188 | double _intercept; // constant term |
duke@435 | 189 | double _slope; // slope |
duke@435 | 190 | // The weighted averages are not currently used but perhaps should |
duke@435 | 191 | // be used to get decaying averages. |
duke@435 | 192 | AdaptiveWeightedAverage _mean_x; // weighted mean of independent variable |
duke@435 | 193 | AdaptiveWeightedAverage _mean_y; // weighted mean of dependent variable |
duke@435 | 194 | |
duke@435 | 195 | public: |
duke@435 | 196 | LinearLeastSquareFit(unsigned weight); |
duke@435 | 197 | void update(double x, double y); |
duke@435 | 198 | double y(double x); |
duke@435 | 199 | double slope() { return _slope; } |
duke@435 | 200 | // Methods to decide if a change in the dependent variable will |
duke@435 | 201 | // achive a desired goal. Note that these methods are not |
duke@435 | 202 | // complementary and both are needed. |
duke@435 | 203 | bool decrement_will_decrease(); |
duke@435 | 204 | bool increment_will_decrease(); |
duke@435 | 205 | }; |
duke@435 | 206 | |
duke@435 | 207 | class GCPauseTimer : StackObj { |
duke@435 | 208 | elapsedTimer* _timer; |
duke@435 | 209 | public: |
duke@435 | 210 | GCPauseTimer(elapsedTimer* timer) { |
duke@435 | 211 | _timer = timer; |
duke@435 | 212 | _timer->stop(); |
duke@435 | 213 | } |
duke@435 | 214 | ~GCPauseTimer() { |
duke@435 | 215 | _timer->start(); |
duke@435 | 216 | } |
duke@435 | 217 | }; |
stefank@2314 | 218 | |
stefank@2314 | 219 | #endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_GCUTIL_HPP |