29
29
import org .graalvm .word .WordFactory ;
30
30
31
31
import com .oracle .svm .core .heap .GCCause ;
32
- import com .oracle .svm .core .option .HostedOptionKey ;
32
+ import com .oracle .svm .core .option .RuntimeOptionKey ;
33
33
import com .oracle .svm .core .util .UnsignedUtils ;
34
34
35
35
/**
@@ -41,14 +41,16 @@ class AggressiveShrinkCollectionPolicy extends AdaptiveCollectionPolicy {
41
41
public static final class Options {
42
42
@ Option (help = "Ratio of used bytes to total allocated bytes for eden space. Setting it to a smaller value " +
43
43
"will trade more triggered hinted GCs for less resident set size." ) //
44
- public static final HostedOptionKey <Double > UsedEdenProportionThreshold = new HostedOptionKey <>(0.75D );
44
+ public static final RuntimeOptionKey <Double > UsedEdenProportionThreshold = new RuntimeOptionKey <>(0.75D );
45
45
@ Option (help = "Soft upper limit for used eden size. The hinted GC will be performed if the used eden size " +
46
46
"exceeds this value." ) //
47
- public static final HostedOptionKey < Integer > ExpectedEdenSize = new HostedOptionKey <>(32 * 1024 * 1024 );
47
+ public static final RuntimeOptionKey < Long > ExpectedEdenSize = new RuntimeOptionKey <>(32L * 1024L * 1024L );
48
48
}
49
49
50
- protected static final UnsignedWord INITIAL_HEAP_SIZE = WordFactory .unsigned (64 * 1024 * 1024 );
51
- protected static final UnsignedWord FULL_GC_BONUS = WordFactory .unsigned (2 * 1024 * 1024 );
50
+ protected static final UnsignedWord INITIAL_HEAP_SIZE = WordFactory .unsigned (64L * 1024L * 1024L );
51
+ protected static final UnsignedWord FULL_GC_BONUS = WordFactory .unsigned (2L * 1024L * 1024L );
52
+
53
+ protected static final UnsignedWord MAXIMUM_HEAP_SIZE = WordFactory .unsigned (16L * 1024L * 1024L * 1024L );
52
54
53
55
private UnsignedWord sizeBefore = WordFactory .zero ();
54
56
private GCCause lastGCCause = null ;
@@ -73,7 +75,7 @@ public boolean shouldCollectOnRequest(GCCause cause, boolean fullGC) {
73
75
// memory usage point.
74
76
edenUsedBytes = edenUsedBytes .add (FULL_GC_BONUS );
75
77
}
76
- return edenUsedBytes .aboveOrEqual (Options .ExpectedEdenSize .getValue ()) ||
78
+ return edenUsedBytes .aboveOrEqual (WordFactory . unsigned ( Options .ExpectedEdenSize .getValue () )) ||
77
79
(UnsignedUtils .toDouble (edenUsedBytes ) / UnsignedUtils .toDouble (edenSize ) >= Options .UsedEdenProportionThreshold .getValue ());
78
80
}
79
81
return super .shouldCollectOnRequest (cause , fullGC );
@@ -84,6 +86,15 @@ protected UnsignedWord getInitialHeapSize() {
84
86
return INITIAL_HEAP_SIZE ;
85
87
}
86
88
89
+ @ Override
90
+ public UnsignedWord getMaximumHeapSize () {
91
+ UnsignedWord initialSetup = super .getMaximumHeapSize ();
92
+ if (initialSetup .aboveThan (MAXIMUM_HEAP_SIZE )) {
93
+ return MAXIMUM_HEAP_SIZE ;
94
+ }
95
+ return initialSetup ;
96
+ }
97
+
87
98
@ Override
88
99
public void onCollectionBegin (boolean completeCollection , long requestingNanoTime ) {
89
100
sizeBefore = GCImpl .getChunkBytes ();
@@ -125,7 +136,10 @@ protected void computeEdenSpaceSize(boolean completeCollection, GCCause cause) {
125
136
} else {
126
137
UnsignedWord sizeAfter = GCImpl .getChunkBytes ();
127
138
if (sizeBefore .notEqual (0 ) && sizeBefore .belowThan (sizeAfter .multiply (2 ))) {
128
- edenSize = alignUp (edenSize .multiply (2 ));
139
+ UnsignedWord newEdenSize = UnsignedUtils .min (getMaximumEdenSize (), alignUp (edenSize .multiply (2 )));
140
+ if (edenSize .belowThan (newEdenSize )) {
141
+ edenSize = newEdenSize ;
142
+ }
129
143
} else {
130
144
super .computeEdenSpaceSize (completeCollection , cause );
131
145
}
0 commit comments