Skip to content

Commit 3426504

Browse files
committed
Testing: code cache assumption.
1 parent c0291f8 commit 3426504

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@
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.code.UntetheredCodeInfoAccess;
35+
import com.oracle.svm.core.genscavenge.compacting.ObjectMoveInfo;
3436
import com.oracle.svm.core.heap.ObjectReferenceVisitor;
37+
import com.oracle.svm.core.util.VMError;
38+
39+
import jdk.graal.compiler.word.Word;
3540

3641
/**
3742
* Before compaction, updates the same references that were visited by
@@ -54,6 +59,8 @@ public boolean visitCode(CodeInfo codeInfo) {
5459

5560
int state = CodeInfoAccess.getState(codeInfo);
5661
if (state == CodeInfo.STATE_UNREACHABLE || state == CodeInfo.STATE_READY_FOR_INVALIDATION) {
62+
Object tether = UntetheredCodeInfoAccess.getTetherUnsafe(codeInfo);
63+
VMError.guarantee(tether != null && !isReachable(tether));
5764
/*
5865
* The code will be freed during this collection, but we need to make sure that all the
5966
* objects that are accessed during the invalidation remain accessible. Those objects
@@ -68,4 +75,21 @@ public boolean visitCode(CodeInfo codeInfo) {
6875
RuntimeCodeInfoAccess.walkWeakReferences(codeInfo, visitor);
6976
return true;
7077
}
78+
79+
/**
80+
* @return {code true} if the object will survive this collection, otherwise {@code false}.
81+
*/
82+
public static boolean isReachable(Object tether) {
83+
if (HeapImpl.getHeapImpl().isInImageHeap(tether)) {
84+
return true;
85+
}
86+
87+
Space space = HeapChunk.getSpace(HeapChunk.getEnclosingHeapChunk(tether));
88+
if (space == null || !space.isOldSpace()) {
89+
return false;
90+
}
91+
92+
Word ptr = Word.objectToUntrackedPointer(tether);
93+
return ObjectMoveInfo.getNewObjectAddress(ptr).isNonNull();
94+
}
7195
}

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)