Skip to content

Commit ff2e9ae

Browse files
committed
[GR-32616] [GR-32512] GC improvements and adaptive policy prototype.
PullRequest: graal/9358
2 parents 30a7258 + db1b88c commit ff2e9ae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2831
-948
lines changed

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/AbstractCollectionPolicy.java

Lines changed: 388 additions & 0 deletions
Large diffs are not rendered by default.

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/AdaptiveCollectionPolicy.java

Lines changed: 557 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/*
2+
* Copyright (c) 2021, 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
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
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package com.oracle.svm.core.genscavenge;
26+
27+
import org.graalvm.word.UnsignedWord;
28+
29+
import com.oracle.svm.core.util.UnsignedUtils;
30+
31+
/**
32+
* A weighted average maintains a running, weighted average of some floating-point value.
33+
*
34+
* The average is adaptive in that we smooth it for the initial samples; we don't use the weight
35+
* until we have enough samples for it to be meaningful.
36+
*
37+
* This serves as our best estimate of a future unknown.
38+
*/
39+
class AdaptiveWeightedAverage {
40+
static final int OLD_THRESHOLD = 100;
41+
42+
private final int weight;
43+
44+
private double average;
45+
private long sampleCount;
46+
private boolean isOld;
47+
48+
AdaptiveWeightedAverage(int weight) {
49+
this(weight, 0);
50+
}
51+
52+
AdaptiveWeightedAverage(int weight, double avg) {
53+
this.weight = weight;
54+
this.average = avg;
55+
}
56+
57+
public double getAverage() {
58+
return average;
59+
}
60+
61+
public void sample(double value) {
62+
sampleCount++;
63+
if (!isOld && sampleCount > OLD_THRESHOLD) {
64+
isOld = true;
65+
}
66+
average = computeAdaptiveAverage(value, average);
67+
}
68+
69+
public final void sample(UnsignedWord value) {
70+
sample(UnsignedUtils.toDouble(value));
71+
}
72+
73+
protected double computeAdaptiveAverage(double sample, double avg) {
74+
/*
75+
* We smoothen the samples by not using weight directly until we've had enough data to make
76+
* it meaningful. We'd like the first weight used to be 1, the second to be 1/2, etc until
77+
* we have OLD_THRESHOLD/weight samples.
78+
*/
79+
long countWeight = 0;
80+
if (!isOld) { // avoid division by zero if the counter wraps
81+
countWeight = OLD_THRESHOLD / sampleCount;
82+
}
83+
long adaptiveWeight = Math.max(weight, countWeight);
84+
return expAvg(avg, sample, adaptiveWeight);
85+
}
86+
87+
private static double expAvg(double avg, double sample, long adaptiveWeight) {
88+
assert adaptiveWeight <= 100 : "weight must be a percentage";
89+
return (100.0 - adaptiveWeight) * avg / 100.0 + adaptiveWeight * sample / 100.0;
90+
}
91+
}
92+
93+
/**
94+
* A weighted average that includes a deviation from the average, some multiple of which is added to
95+
* the average.
96+
*
97+
* This serves as our best estimate of an upper bound on a future unknown.
98+
*/
99+
class AdaptivePaddedAverage extends AdaptiveWeightedAverage {
100+
private final int padding;
101+
private final boolean noZeroDeviations;
102+
103+
private double paddedAverage;
104+
private double deviation;
105+
106+
AdaptivePaddedAverage(int weight, int padding) {
107+
this(weight, padding, false);
108+
}
109+
110+
/**
111+
* @param noZeroDeviations do not update deviations when a sample is zero. The average is
112+
* allowed to change. This is to prevent zero samples from drastically changing the
113+
* padded average.
114+
*/
115+
AdaptivePaddedAverage(int weight, int padding, boolean noZeroDeviations) {
116+
super(weight);
117+
this.padding = padding;
118+
this.noZeroDeviations = noZeroDeviations;
119+
}
120+
121+
@Override
122+
public void sample(double value) {
123+
super.sample(value);
124+
double average = super.getAverage();
125+
if (value != 0 || !noZeroDeviations) {
126+
deviation = computeAdaptiveAverage(Math.abs(value - average), deviation);
127+
}
128+
paddedAverage = average + padding * deviation;
129+
}
130+
131+
public double getPaddedAverage() {
132+
return paddedAverage;
133+
}
134+
135+
public double getDeviation() {
136+
return deviation;
137+
}
138+
}

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/AlignedHeapChunk.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public static AlignedHeader getEnclosingChunk(Object obj) {
124124
}
125125

126126
public static AlignedHeader getEnclosingChunkFromObjectPointer(Pointer ptr) {
127-
return (AlignedHeader) PointerUtils.roundDown(ptr, HeapPolicy.getAlignedHeapChunkAlignment());
127+
return (AlignedHeader) PointerUtils.roundDown(ptr, HeapParameters.getAlignedHeapChunkAlignment());
128128
}
129129

130130
/** Return the offset of an object within the objects part of a chunk. */

0 commit comments

Comments
 (0)