From f1e4ec8d890f907ac70c1e312fbdd06834e9f54b Mon Sep 17 00:00:00 2001 From: Peter Hofer Date: Fri, 3 May 2024 19:50:37 +0200 Subject: [PATCH] fixup! Revisit newly added files. --- .../RuntimeCodeCacheFixupWalker.java | 30 +++++-------------- .../compacting/ObjectMoveInfo.java | 6 ++-- .../compacting/PlanningVisitor.java | 4 ++- 3 files changed, 14 insertions(+), 26 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/RuntimeCodeCacheFixupWalker.java b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/RuntimeCodeCacheFixupWalker.java index cdab58f1063ee..920f2519ae50b 100644 --- a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/RuntimeCodeCacheFixupWalker.java +++ b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/RuntimeCodeCacheFixupWalker.java @@ -28,21 +28,16 @@ import org.graalvm.nativeimage.Platforms; import com.oracle.svm.core.code.CodeInfo; -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.genscavenge.compacting.ObjectRefFixupVisitor; -/** - * Before compaction, updates the same references that were visited by - * {@link RuntimeCodeCacheWalker} during the mark phase. - */ +/** 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; } @@ -52,19 +47,10 @@ public boolean visitCode(CodeInfo codeInfo) { return true; } - int state = CodeInfoAccess.getState(codeInfo); - assert state != CodeInfo.STATE_INVALIDATED : "should not be observable here"; - 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; - } - - /* The CodeInfo remains valid, so we need to fix up all references. */ + /* + * Whether this CodeInfo remains valid or will be invalidated or freed during this GC, we + * update all its references, including clearing those to objects that do not survive. + */ RuntimeCodeInfoAccess.walkStrongReferences(codeInfo, visitor); RuntimeCodeInfoAccess.walkWeakReferences(codeInfo, visitor); return true; diff --git a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/compacting/ObjectMoveInfo.java b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/compacting/ObjectMoveInfo.java index dcfa7d08e857b..33503e44c5588 100644 --- a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/compacting/ObjectMoveInfo.java +++ b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/compacting/ObjectMoveInfo.java @@ -80,9 +80,9 @@ public final class ObjectMoveInfo { static void setNewAddress(Pointer objSeqStart, Pointer newAddress) { if (useCompressedLayout()) { - int alignment = ConfigurationValues.getObjectLayout().getAlignment(); - UnsignedWord offset = newAddress.subtract(objSeqStart).unsignedDivide(alignment); - objSeqStart.writeInt(-8, (int) offset.rawValue()); + long offset = newAddress.subtract(objSeqStart).rawValue(); + offset /= ConfigurationValues.getObjectLayout().getAlignment(); + objSeqStart.writeInt(-8, (int) offset); } else { objSeqStart.writeWord(-16, newAddress); } diff --git a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/compacting/PlanningVisitor.java b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/compacting/PlanningVisitor.java index 4473f77c3ed9e..f728c97c04274 100644 --- a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/compacting/PlanningVisitor.java +++ b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/compacting/PlanningVisitor.java @@ -165,8 +165,10 @@ public boolean visitChunk(AlignedHeapChunk.AlignedHeader chunk) { private Pointer allocate(UnsignedWord size) { Pointer p = allocPointer; allocPointer = allocPointer.add(size); - if (allocPointer.aboveOrEqual(AlignedHeapChunk.getObjectsEnd(allocChunk))) { + if (allocPointer.aboveThan(AlignedHeapChunk.getObjectsEnd(allocChunk))) { allocChunk = HeapChunk.getNext(allocChunk); + assert allocChunk.isNonNull(); + p = AlignedHeapChunk.getObjectsStart(allocChunk); allocPointer = p.add(size); }