36
36
import com .oracle .svm .core .os .CommittedMemoryProvider ;
37
37
import com .oracle .svm .core .thread .JavaSpinLockUtils ;
38
38
import com .oracle .svm .core .thread .VMOperation ;
39
+ import com .oracle .svm .core .util .BasedOnJDKFile ;
39
40
import com .oracle .svm .core .util .UnsignedUtils ;
40
41
import com .oracle .svm .core .util .VMError ;
41
42
49
50
*/
50
51
abstract class AbstractCollectionPolicy implements CollectionPolicy {
51
52
52
- protected static final int MIN_SPACE_SIZE_IN_ALIGNED_CHUNKS = 8 ;
53
+ protected static final int MIN_SPACE_SIZE_AS_NUMBER_OF_ALIGNED_CHUNKS = 8 ;
54
+
55
+ @ BasedOnJDKFile ("https://github.com/openjdk/jdk/blob/jdk-25+20/src/hotspot/share/gc/shared/gc_globals.hpp#L572-L575" ) //
53
56
protected static final int MAX_TENURING_THRESHOLD = 15 ;
54
57
55
58
@ Platforms (Platform .HOSTED_ONLY .class )
@@ -68,15 +71,19 @@ static int getMaxSurvivorSpaces(Integer userValue) {
68
71
* Don't change these values individually without carefully going over their occurrences in
69
72
* HotSpot source code, there are dependencies between them that are not handled in our code.
70
73
*/
74
+ @ BasedOnJDKFile ("https://github.com/openjdk/jdk/blob/jdk-25+20/src/hotspot/share/gc/shared/gc_globals.hpp#L413-L415" ) //
71
75
protected static final int INITIAL_SURVIVOR_RATIO = 8 ;
76
+ @ BasedOnJDKFile ("https://github.com/openjdk/jdk/blob/jdk-25+20/src/hotspot/share/gc/shared/gc_globals.hpp#L409-L411" ) //
72
77
protected static final int MIN_SURVIVOR_RATIO = 3 ;
73
- protected static final int DEFAULT_TIME_WEIGHT = 25 ; // -XX:AdaptiveTimeWeight
78
+ @ BasedOnJDKFile ("https://github.com/openjdk/jdk/blob/jdk-25+20/src/hotspot/share/gc/shared/gc_globals.hpp#L340-L342" ) //
79
+ protected static final int ADAPTIVE_TIME_WEIGHT = 25 ;
74
80
75
81
/* Constants to compute defaults for values which can be set through existing options. */
76
82
protected static final UnsignedWord INITIAL_HEAP_SIZE = Word .unsigned (128 * 1024 * 1024 );
77
- protected static final int NEW_RATIO = 2 ; // HotSpot: -XX:NewRatio
83
+ @ BasedOnJDKFile ("https://github.com/openjdk/jdk/blob/jdk-25+20/src/hotspot/share/gc/shared/gc_globals.hpp#L554-L556" ) //
84
+ protected static final int NEW_RATIO = 2 ;
78
85
79
- protected final AdaptiveWeightedAverage avgYoungGenAlignedChunkFraction = new AdaptiveWeightedAverage (DEFAULT_TIME_WEIGHT );
86
+ protected final AdaptiveWeightedAverage avgYoungGenAlignedChunkFraction = new AdaptiveWeightedAverage (ADAPTIVE_TIME_WEIGHT );
80
87
81
88
private final int initialNewRatio ;
82
89
protected UnsignedWord survivorSize ;
@@ -130,7 +137,7 @@ static boolean isAligned(UnsignedWord size) {
130
137
131
138
@ Fold
132
139
static UnsignedWord minSpaceSize () {
133
- return getAlignment ().multiply (MIN_SPACE_SIZE_IN_ALIGNED_CHUNKS );
140
+ return HeapParameters . getAlignedHeapChunkSize ().multiply (MIN_SPACE_SIZE_AS_NUMBER_OF_ALIGNED_CHUNKS );
134
141
}
135
142
136
143
@ Uninterruptible (reason = "Called from uninterruptible code." , mayBeInlined = true )
@@ -221,6 +228,7 @@ public final UnsignedWord getInitialEdenSize() {
221
228
222
229
@ Override
223
230
@ Uninterruptible (reason = "Called from uninterruptible code." , mayBeInlined = true )
231
+ @ BasedOnJDKFile ("https://github.com/openjdk/jdk/blob/jdk-25+21/src/hotspot/share/gc/parallel/psYoungGen.cpp#L104-L116" )
224
232
public final UnsignedWord getMaximumEdenSize () {
225
233
guaranteeSizeParametersInitialized ();
226
234
return alignDown (sizes .maxYoungSize .subtract (survivorSize .multiply (2 )));
@@ -295,9 +303,8 @@ public UnsignedWord getMaximumFreeAlignedChunksSize() {
295
303
assert VMOperation .isGCInProgress () : "use only during GC" ;
296
304
guaranteeSizeParametersInitialized ();
297
305
/*
298
- * Keep chunks ready for allocations in eden and for the survivor to-spaces during young
299
- * collections (although we might keep too many aligned chunks when large objects in
300
- * unaligned chunks are also allocated). We could alternatively return
306
+ * Keep chunks ready for allocations in eden as well as for copying the objects currently in
307
+ * survivor spaces in a future collection. We could alternatively return
301
308
* getCurrentHeapCapacity() to have chunks ready during full GCs as well.
302
309
*/
303
310
UnsignedWord total = edenSize .add (HeapImpl .getAccounting ().getSurvivorUsedBytes ());
@@ -331,6 +338,8 @@ public final UnsignedWord getMinimumHeapSize() {
331
338
@ Uninterruptible (reason = "Called from uninterruptible code." , mayBeInlined = true )
332
339
protected abstract long gcCount ();
333
340
341
+ @ BasedOnJDKFile ("https://github.com/openjdk/jdk/blob/jdk-25+21/src/hotspot/share/gc/shared/genArguments.cpp#L195-L310" )
342
+ @ BasedOnJDKFile ("https://github.com/openjdk/jdk/blob/jdk-25+21/src/hotspot/share/gc/parallel/psYoungGen.cpp#L146-L168" )
334
343
protected SizeParameters computeSizeParameters (SizeParameters existing ) {
335
344
UnsignedWord minYoungSpaces = minSpaceSize (); // eden
336
345
if (HeapParameters .getMaxSurvivorSpaces () > 0 ) {
@@ -386,9 +395,10 @@ protected SizeParameters computeSizeParameters(SizeParameters existing) {
386
395
/*
387
396
* In HotSpot, this is the reserved capacity of each of the survivor From and To spaces,
388
397
* i.e., together they occupy 2x this size. Our chunked heap doesn't reserve memory, so
389
- * we never occupy more than 1x this size for survivors except during collections.
390
- * However, this is inconsistent with how we interpret the maximum size of the old
391
- * generation, which we can exceed while copying during collections.
398
+ * we never occupy more than 1x this size for survivors except during collections. We
399
+ * reserve 2x regardless (see below). However, this is inconsistent with how we
400
+ * interpret the maximum size of the old generation, which we can exceed the same way
401
+ * while copying during collections, but reserve only 1x its size.
392
402
*/
393
403
initialSurvivor = initialYoung .unsignedDivide (AbstractCollectionPolicy .INITIAL_SURVIVOR_RATIO );
394
404
initialSurvivor = minSpaceSize (alignDown (initialSurvivor ));
@@ -448,6 +458,7 @@ private SizeParameters(UnsignedWord maxHeapSize, UnsignedWord maxYoungSize, Unsi
448
458
}
449
459
450
460
@ Uninterruptible (reason = "Called from uninterruptible code." , mayBeInlined = true )
461
+ @ BasedOnJDKFile ("https://github.com/openjdk/jdk/blob/jdk-25+21/src/hotspot/share/gc/parallel/psYoungGen.cpp#L104-L116" )
451
462
UnsignedWord maxSurvivorSize () {
452
463
if (HeapParameters .getMaxSurvivorSpaces () == 0 ) {
453
464
return Word .zero ();
0 commit comments