Skip to content

Commit 3f1f622

Browse files
committed
[GR-51205] Avoid needlessly rescanning objects.
PullRequest: graal/16505
2 parents c7d9ddb + 983e277 commit 3f1f622

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ static boolean walkObjects(AlignedHeader that, ObjectVisitor visitor) {
149149

150150
@AlwaysInline("GC performance")
151151
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
152-
static boolean walkObjectsInline(AlignedHeader that, ObjectVisitor visitor) {
153-
return HeapChunk.walkObjectsFromInline(that, getObjectsStart(that), visitor);
152+
static boolean walkObjectsFromInline(AlignedHeader that, Pointer start, ObjectVisitor visitor) {
153+
return HeapChunk.walkObjectsFromInline(that, start, visitor);
154154
}
155155

156156
@Fold

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,23 +87,27 @@ void walkGreyObjects() {
8787
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
8888
private void walkAlignedGreyObjects() {
8989
AlignedHeapChunk.AlignedHeader aChunk;
90+
Pointer aStart;
9091
if (alignedHeapChunk.isNull() && alignedTop.isNull()) {
9192
/* If the snapshot is empty, then I have to walk from the beginning of the Space. */
9293
aChunk = space.getFirstAlignedHeapChunk();
94+
aStart = (aChunk.isNonNull() ? AlignedHeapChunk.getObjectsStart(aChunk) : WordFactory.nullPointer());
9395
} else {
9496
/* Otherwise walk Objects that arrived after the snapshot. */
9597
aChunk = alignedHeapChunk;
98+
aStart = alignedTop;
9699
}
97100
/* Visit Objects in the AlignedChunks. */
98101
GreyToBlackObjectVisitor visitor = GCImpl.getGCImpl().getGreyToBlackObjectVisitor();
99102
if (aChunk.isNonNull()) {
100103
AlignedHeapChunk.AlignedHeader lastChunk;
101104
do {
102105
lastChunk = aChunk;
103-
if (!AlignedHeapChunk.walkObjectsInline(aChunk, visitor)) {
106+
if (!AlignedHeapChunk.walkObjectsFromInline(aChunk, aStart, visitor)) {
104107
throw VMError.shouldNotReachHereAtRuntime();
105108
}
106109
aChunk = HeapChunk.getNext(aChunk);
110+
aStart = (aChunk.isNonNull() ? AlignedHeapChunk.getObjectsStart(aChunk) : WordFactory.nullPointer());
107111
} while (aChunk.isNonNull());
108112

109113
/* Move the scan point. */

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,20 +297,20 @@ private static SignedWord offsetFromPointer(Header<?> that, PointerBase pointer)
297297
}
298298

299299
@NeverInline("Not performance critical")
300-
public static boolean walkObjectsFrom(Header<?> that, Pointer offset, ObjectVisitor visitor) {
301-
return walkObjectsFromInline(that, offset, visitor);
300+
public static boolean walkObjectsFrom(Header<?> that, Pointer start, ObjectVisitor visitor) {
301+
return walkObjectsFromInline(that, start, visitor);
302302
}
303303

304304
@AlwaysInline("GC performance")
305305
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
306-
public static boolean walkObjectsFromInline(Header<?> that, Pointer startOffset, ObjectVisitor visitor) {
307-
Pointer offset = startOffset;
308-
while (offset.belowThan(getTopPointer(that))) { // crucial: top can move, so always re-read
309-
Object obj = offset.toObject();
306+
public static boolean walkObjectsFromInline(Header<?> that, Pointer start, ObjectVisitor visitor) {
307+
Pointer p = start;
308+
while (p.belowThan(getTopPointer(that))) { // crucial: top can move, so always re-read
309+
Object obj = p.toObject();
310310
if (!callVisitor(visitor, obj)) {
311311
return false;
312312
}
313-
offset = offset.add(LayoutEncoding.getSizeFromObjectInlineInGC(obj));
313+
p = p.add(LayoutEncoding.getSizeFromObjectInlineInGC(obj));
314314
}
315315
return true;
316316
}

0 commit comments

Comments
 (0)