Skip to content

Commit 615b4c1

Browse files
committed
fixup! Revisit newly added files.
1 parent c0291f8 commit 615b4c1

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

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

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,19 @@
3131
import com.oracle.svm.core.code.CodeInfoAccess;
3232
import com.oracle.svm.core.code.RuntimeCodeCache.CodeInfoVisitor;
3333
import com.oracle.svm.core.code.RuntimeCodeInfoAccess;
34-
import com.oracle.svm.core.heap.ObjectReferenceVisitor;
34+
import com.oracle.svm.core.code.UntetheredCodeInfoAccess;
35+
import com.oracle.svm.core.genscavenge.compacting.ObjectMoveInfo;
36+
import com.oracle.svm.core.genscavenge.compacting.ObjectRefFixupVisitor;
3537

36-
/**
37-
* Before compaction, updates the same references that were visited by
38-
* {@link RuntimeCodeCacheWalker} during the mark phase.
39-
*/
38+
import jdk.graal.compiler.word.Word;
39+
40+
/** Before compaction, updates references from {@link CodeInfo} structures. */
4041
final class RuntimeCodeCacheFixupWalker implements CodeInfoVisitor {
4142

42-
private final ObjectReferenceVisitor visitor;
43+
private final ObjectRefFixupVisitor visitor;
4344

4445
@Platforms(Platform.HOSTED_ONLY.class)
45-
RuntimeCodeCacheFixupWalker(ObjectReferenceVisitor visitor) {
46+
RuntimeCodeCacheFixupWalker(ObjectRefFixupVisitor visitor) {
4647
this.visitor = visitor;
4748
}
4849

@@ -54,18 +55,33 @@ public boolean visitCode(CodeInfo codeInfo) {
5455

5556
int state = CodeInfoAccess.getState(codeInfo);
5657
if (state == CodeInfo.STATE_UNREACHABLE || state == CodeInfo.STATE_READY_FOR_INVALIDATION) {
57-
/*
58-
* The code will be freed during this collection, but we need to make sure that all the
59-
* objects that are accessed during the invalidation remain accessible. Those objects
60-
* can only be collected in a subsequent garbage collection.
61-
*/
62-
RuntimeCodeInfoAccess.walkObjectFields(codeInfo, visitor);
63-
return true;
58+
Object tether = UntetheredCodeInfoAccess.getTetherUnsafe(codeInfo);
59+
if (tether != null && !isReachable(tether)) {
60+
/*
61+
* The CodeInfo's state was changed to unreachable or to-be-invalidated during the
62+
* mark phase, so we only need to visit references that will be accessed before the
63+
* unmanaged memory is freed.
64+
*/
65+
RuntimeCodeInfoAccess.walkObjectFields(codeInfo, visitor);
66+
return true;
67+
}
6468
}
6569

6670
/* The CodeInfo remains valid, so we need to fix up all references. */
6771
RuntimeCodeInfoAccess.walkStrongReferences(codeInfo, visitor);
6872
RuntimeCodeInfoAccess.walkWeakReferences(codeInfo, visitor);
6973
return true;
7074
}
75+
76+
public static boolean isReachable(Object tether) {
77+
if (HeapImpl.getHeapImpl().isInImageHeap(tether)) {
78+
return true;
79+
}
80+
Space space = HeapChunk.getSpace(HeapChunk.getEnclosingHeapChunk(tether));
81+
if (space == null || !space.isOldSpace()) {
82+
return false;
83+
}
84+
Word ptr = Word.objectToUntrackedPointer(tether);
85+
return ObjectMoveInfo.getNewObjectAddress(ptr).isNonNull();
86+
}
7187
}

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/compacting/ObjectMoveInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public static void walkObjects(AlignedHeapChunk.AlignedHeader chunkHeader, Objec
181181
}
182182

183183
@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
184-
static Pointer getNewObjectAddress(Pointer objPointer) {
184+
public static Pointer getNewObjectAddress(Pointer objPointer) {
185185
assert ObjectHeaderImpl.isAlignedObject(objPointer.toObject());
186186

187187
AlignedHeapChunk.AlignedHeader chunk = AlignedHeapChunk.getEnclosingChunkFromObjectPointer(objPointer);

0 commit comments

Comments
 (0)