Skip to content

Commit a11a9be

Browse files
[GR-47580] Initialize the physical memory size eagerly.
PullRequest: graal/15260
2 parents cd7d9ac + 7ddcb90 commit a11a9be

Some content is hidden

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

41 files changed

+546
-569
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public boolean shouldCollectOnAllocation() {
9191
if (sizes == null) {
9292
return false; // updateSizeParameters() has never been called
9393
}
94-
UnsignedWord edenUsed = HeapImpl.getHeapImpl().getAccounting().getEdenUsedBytes();
94+
UnsignedWord edenUsed = HeapImpl.getAccounting().getEdenUsedBytes();
9595
return edenUsed.aboveOrEqual(edenSize);
9696
}
9797

@@ -144,8 +144,6 @@ protected void guaranteeSizeParametersInitialized() {
144144

145145
@Override
146146
public void updateSizeParameters() {
147-
PhysicalMemory.tryInitialize();
148-
149147
SizeParameters params = computeSizeParameters(sizes);
150148
SizeParameters previous = sizes;
151149
if (previous != null && params.equal(previous)) {
@@ -301,7 +299,7 @@ public int getTenuringAge() {
301299
public void onCollectionBegin(boolean completeCollection, long requestingNanoTime) {
302300
// Capture the fraction of bytes in aligned chunks at the start to include all allocated
303301
// (also dead) objects, because we use it to reserve aligned chunks for future allocations
304-
UnsignedWord youngChunkBytes = GCImpl.getGCImpl().getAccounting().getYoungChunkBytesBefore();
302+
UnsignedWord youngChunkBytes = GCImpl.getAccounting().getYoungChunkBytesBefore();
305303
if (youngChunkBytes.notEqual(0)) {
306304
UnsignedWord youngAlignedChunkBytes = HeapImpl.getHeapImpl().getYoungGeneration().getAlignedChunkBytes();
307305
avgYoungGenAlignedChunkFraction.sample(UnsignedUtils.toDouble(youngAlignedChunkBytes) / UnsignedUtils.toDouble(youngChunkBytes));

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ UnsignedWord getInitialValue() {
6969

7070
abstract UnsignedWord getMaximumValue();
7171

72-
abstract void afterCollection(GCAccounting accounting);
72+
abstract void beforeCollection();
73+
74+
abstract void afterCollection();
7375

7476
MemoryUsage memoryUsage(UnsignedWord usedAndCommitted) {
7577
return new MemoryUsage(getInitialValue().rawValue(), usedAndCommitted.rawValue(), usedAndCommitted.rawValue(), getMaximumValue().rawValue());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ public void onCollectionEnd(boolean completeCollection, GCCause cause) { // {maj
420420
timer.reset();
421421
timer.open();
422422

423-
GCAccounting accounting = GCImpl.getGCImpl().getAccounting();
423+
GCAccounting accounting = GCImpl.getAccounting();
424424
UnsignedWord oldLive = accounting.getOldGenerationAfterChunkBytes();
425425
oldSizeExceededInPreviousCollection = oldLive.aboveThan(oldSize);
426426

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ protected static UnsignedWord m(long bytes) {
5858

5959
@Override
6060
public boolean shouldCollectOnAllocation() {
61-
UnsignedWord youngUsed = HeapImpl.getHeapImpl().getAccounting().getYoungUsedBytes();
61+
UnsignedWord youngUsed = HeapImpl.getAccounting().getYoungUsedBytes();
6262
return youngUsed.aboveOrEqual(getMaximumYoungGenerationSize());
6363
}
6464

@@ -79,12 +79,6 @@ public void ensureSizeParametersInitialized() {
7979

8080
@Override
8181
public void updateSizeParameters() {
82-
// Sample the physical memory size, before the first GC but after some allocation.
83-
UnsignedWord allocationBeforeUpdate = WordFactory.unsigned(SerialAndEpsilonGCOptions.AllocationBeforePhysicalMemorySize.getValue());
84-
if (GCImpl.getGCImpl().getCollectionEpoch().equal(WordFactory.zero()) &&
85-
HeapImpl.getHeapImpl().getAccounting().getYoungUsedBytes().aboveOrEqual(allocationBeforeUpdate)) {
86-
PhysicalMemory.tryInitialize();
87-
}
8882
// Size parameters are recomputed from current values whenever they are queried
8983
}
9084

@@ -287,15 +281,15 @@ public boolean shouldCollectCompletely(boolean followingIncrementalCollection) {
287281
private UnsignedWord estimateUsedHeapAtNextIncrementalCollection() {
288282
UnsignedWord currentYoungBytes = HeapImpl.getHeapImpl().getYoungGeneration().getChunkBytes();
289283
UnsignedWord maxYoungBytes = getMaximumYoungGenerationSize();
290-
UnsignedWord oldBytes = GCImpl.getGCImpl().getAccounting().getOldGenerationAfterChunkBytes();
284+
UnsignedWord oldBytes = GCImpl.getAccounting().getOldGenerationAfterChunkBytes();
291285
return currentYoungBytes.add(maxYoungBytes).add(oldBytes);
292286
}
293287

294288
private static boolean enoughTimeSpentOnIncrementalGCs() {
295289
int incrementalWeight = SerialGCOptions.PercentTimeInIncrementalCollection.getValue();
296290
assert incrementalWeight >= 0 && incrementalWeight <= 100 : "BySpaceAndTimePercentTimeInIncrementalCollection should be in the range [0..100].";
297291

298-
GCAccounting accounting = GCImpl.getGCImpl().getAccounting();
292+
GCAccounting accounting = GCImpl.getAccounting();
299293
long actualIncrementalNanos = accounting.getIncrementalCollectionTotalNanos();
300294
long completeNanos = accounting.getCompleteCollectionTotalNanos();
301295
long totalNanos = actualIncrementalNanos + completeNanos;

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.graalvm.word.WordFactory;
3131

3232
import com.oracle.svm.core.Uninterruptible;
33-
import com.oracle.svm.core.log.Log;
3433

3534
/**
3635
* Accounting for a {@link Space} or {@link Generation}. For the eden space, the values are
@@ -84,12 +83,6 @@ public UnsignedWord getUnalignedChunkBytes() {
8483
return unalignedChunkBytes;
8584
}
8685

87-
void report(Log reportLog) {
88-
reportLog.string("aligned: ").unsigned(getAlignedChunkBytes()).string("/").unsigned(alignedCount);
89-
reportLog.string(" ");
90-
reportLog.string("unaligned: ").unsigned(unalignedChunkBytes).string("/").unsigned(unalignedCount);
91-
}
92-
9386
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
9487
void noteAlignedHeapChunk() {
9588
alignedCount++;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ public CompleteGarbageCollectorMXBean() {
4848

4949
@Override
5050
public long getCollectionCount() {
51-
return HeapImpl.getGCImpl().getAccounting().getCompleteCollectionCount();
51+
return GCImpl.getAccounting().getCompleteCollectionCount();
5252
}
5353

5454
@Override
5555
public long getCollectionTime() {
56-
long nanos = HeapImpl.getGCImpl().getAccounting().getCompleteCollectionTotalNanos();
56+
long nanos = GCImpl.getAccounting().getCompleteCollectionTotalNanos();
5757
return TimeUtils.roundNanosToMillis(nanos);
5858
}
5959

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

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@
3333
import com.oracle.svm.core.Uninterruptible;
3434

3535
/**
36-
* This data is only updated during a GC.
36+
* Note that this data may be updated up to 3 times during a single VM operation (incremental GC,
37+
* full GC, full GC that treats soft references as weak). Therefore, this class should only be used
38+
* by GC internal code that is aware of this (could result in incorrect "before"/"after" values
39+
* otherwise). Non-GC code should use the class {@link HeapAccounting} instead.
3740
*
3841
* ChunkBytes refer to bytes reserved (but maybe not occupied). ObjectBytes refer to bytes occupied
3942
* by objects.
@@ -50,10 +53,7 @@ public final class GCAccounting {
5053
private boolean lastIncrementalCollectionOverflowedSurvivors = false;
5154

5255
/* Before and after measures. */
53-
private UnsignedWord edenChunkBytesBefore = WordFactory.zero();
54-
private UnsignedWord edenChunkBytesAfter = WordFactory.zero();
5556
private UnsignedWord youngChunkBytesBefore = WordFactory.zero();
56-
private UnsignedWord youngChunkBytesAfter = WordFactory.zero();
5757
private UnsignedWord oldChunkBytesBefore = WordFactory.zero();
5858
private UnsignedWord oldChunkBytesAfter = WordFactory.zero();
5959

@@ -78,10 +78,6 @@ public long getIncrementalCollectionTotalNanos() {
7878
return incrementalCollectionTotalNanos;
7979
}
8080

81-
UnsignedWord getTotalAllocatedChunkBytes() {
82-
return totalAllocatedChunkBytes;
83-
}
84-
8581
public long getCompleteCollectionCount() {
8682
return completeCollectionCount;
8783
}
@@ -90,6 +86,10 @@ public long getCompleteCollectionTotalNanos() {
9086
return completeCollectionTotalNanos;
9187
}
9288

89+
UnsignedWord getTotalAllocatedChunkBytes() {
90+
return totalAllocatedChunkBytes;
91+
}
92+
9393
UnsignedWord getTotalCollectedChunkBytes() {
9494
return totalCollectedChunkBytes;
9595
}
@@ -102,26 +102,14 @@ UnsignedWord getAllocatedObjectBytes() {
102102
return allocatedObjectBytes;
103103
}
104104

105-
public UnsignedWord getOldGenerationAfterChunkBytes() {
105+
UnsignedWord getOldGenerationAfterChunkBytes() {
106106
return oldChunkBytesAfter;
107107
}
108108

109-
UnsignedWord getEdenChunkBytesBefore() {
110-
return edenChunkBytesBefore;
111-
}
112-
113-
UnsignedWord getEdenChunkBytesAfter() {
114-
return edenChunkBytesAfter;
115-
}
116-
117109
UnsignedWord getYoungChunkBytesBefore() {
118110
return youngChunkBytesBefore;
119111
}
120112

121-
UnsignedWord getYoungChunkBytesAfter() {
122-
return youngChunkBytesAfter;
123-
}
124-
125113
UnsignedWord getLastIncrementalCollectionPromotedChunkBytes() {
126114
return lastIncrementalCollectionPromotedChunkBytes;
127115
}
@@ -136,7 +124,6 @@ void beforeCollection(boolean completeCollection) {
136124
YoungGeneration youngGen = heap.getYoungGeneration();
137125
OldGeneration oldGen = heap.getOldGeneration();
138126

139-
edenChunkBytesBefore = youngGen.getEden().getChunkBytes();
140127
youngChunkBytesBefore = youngGen.getChunkBytes();
141128
oldChunkBytesBefore = oldGen.getChunkBytes();
142129

@@ -192,8 +179,7 @@ private void afterCollectionCommon() {
192179
YoungGeneration youngGen = heap.getYoungGeneration();
193180
OldGeneration oldGen = heap.getOldGeneration();
194181

195-
edenChunkBytesAfter = youngGen.getEden().getChunkBytes();
196-
youngChunkBytesAfter = youngGen.getChunkBytes();
182+
UnsignedWord youngChunkBytesAfter = youngGen.getChunkBytes();
197183
oldChunkBytesAfter = oldGen.getChunkBytes();
198184

199185
UnsignedWord beforeChunkBytes = youngChunkBytesBefore.add(oldChunkBytesBefore);
@@ -211,9 +197,14 @@ private void afterCollectionCommon() {
211197
if (SerialGCOptions.PrintGCSummary.getValue()) {
212198
UnsignedWord afterObjectBytesAfter = youngGen.computeObjectBytes().add(oldGen.computeObjectBytes());
213199
UnsignedWord beforeObjectBytes = youngObjectBytesBefore.add(oldObjectBytesBefore);
214-
assert beforeObjectBytes.aboveOrEqual(afterObjectBytesAfter);
215-
UnsignedWord collectedObjectBytes = beforeObjectBytes.subtract(afterObjectBytesAfter);
216-
totalCollectedObjectBytes = totalCollectedObjectBytes.add(collectedObjectBytes);
200+
/*
201+
* Object size may increase (e.g., identity hashcode field may be added to promoted
202+
* objects).
203+
*/
204+
if (beforeObjectBytes.aboveOrEqual(afterObjectBytesAfter)) {
205+
UnsignedWord collectedObjectBytes = beforeObjectBytes.subtract(afterObjectBytesAfter);
206+
totalCollectedObjectBytes = totalCollectedObjectBytes.add(collectedObjectBytes);
207+
}
217208
}
218209
}
219210
}

0 commit comments

Comments
 (0)