Skip to content

Commit

Permalink
fixup! Revisit newly added files.
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-hofer committed May 6, 2024
1 parent c0291f8 commit 615b4c1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,19 @@
import com.oracle.svm.core.code.CodeInfoAccess;
import com.oracle.svm.core.code.RuntimeCodeCache.CodeInfoVisitor;
import com.oracle.svm.core.code.RuntimeCodeInfoAccess;
import com.oracle.svm.core.heap.ObjectReferenceVisitor;
import com.oracle.svm.core.code.UntetheredCodeInfoAccess;
import com.oracle.svm.core.genscavenge.compacting.ObjectMoveInfo;
import com.oracle.svm.core.genscavenge.compacting.ObjectRefFixupVisitor;

/**
* Before compaction, updates the same references that were visited by
* {@link RuntimeCodeCacheWalker} during the mark phase.
*/
import jdk.graal.compiler.word.Word;

/** Before compaction, updates references from {@link CodeInfo} structures. */
final class RuntimeCodeCacheFixupWalker implements CodeInfoVisitor {

private final ObjectReferenceVisitor visitor;
private final ObjectRefFixupVisitor visitor;

@Platforms(Platform.HOSTED_ONLY.class)
RuntimeCodeCacheFixupWalker(ObjectReferenceVisitor visitor) {
RuntimeCodeCacheFixupWalker(ObjectRefFixupVisitor visitor) {
this.visitor = visitor;
}

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

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

/* The CodeInfo remains valid, so we need to fix up all references. */
RuntimeCodeInfoAccess.walkStrongReferences(codeInfo, visitor);
RuntimeCodeInfoAccess.walkWeakReferences(codeInfo, visitor);
return true;
}

public static boolean isReachable(Object tether) {
if (HeapImpl.getHeapImpl().isInImageHeap(tether)) {
return true;
}
Space space = HeapChunk.getSpace(HeapChunk.getEnclosingHeapChunk(tether));
if (space == null || !space.isOldSpace()) {
return false;
}
Word ptr = Word.objectToUntrackedPointer(tether);
return ObjectMoveInfo.getNewObjectAddress(ptr).isNonNull();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public static void walkObjects(AlignedHeapChunk.AlignedHeader chunkHeader, Objec
}

@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
static Pointer getNewObjectAddress(Pointer objPointer) {
public static Pointer getNewObjectAddress(Pointer objPointer) {
assert ObjectHeaderImpl.isAlignedObject(objPointer.toObject());

AlignedHeapChunk.AlignedHeader chunk = AlignedHeapChunk.getEnclosingChunkFromObjectPointer(objPointer);
Expand Down

0 comments on commit 615b4c1

Please sign in to comment.