Skip to content

[GR-67673] Report more information if the heap verification finds a broken reference on the stack. #11720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import com.oracle.svm.core.config.ConfigurationValues;
import com.oracle.svm.core.genscavenge.AlignedHeapChunk.AlignedHeader;
import com.oracle.svm.core.genscavenge.StackVerifier.VerifyFrameReferencesVisitor;
import com.oracle.svm.core.genscavenge.UnalignedHeapChunk.UnalignedHeader;
import com.oracle.svm.core.genscavenge.remset.RememberedSet;
import com.oracle.svm.core.heap.Heap;
Expand Down Expand Up @@ -384,10 +385,11 @@ private static boolean verifyReference(Object parentObject, Pointer reference, P
}

private static void printParent(Object parentObject) {
if (parentObject != null) {
Log.log().string("The object that contains the invalid reference is of type ").string(parentObject.getClass().getName()).newline();
if (parentObject instanceof VerifyFrameReferencesVisitor visitor) {
Log.log().string("The invalid reference is on the stack: sp=").zhex(visitor.getSP()).string(", ip=").zhex(visitor.getIP()).newline();
} else {
Log.log().string("The invalid reference is on the stack").newline();
assert parentObject != null;
Log.log().string("The object that contains the invalid reference is of type ").string(parentObject.getClass().getName()).newline();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void initialize() {
@Override
@RestrictHeapAccess(access = RestrictHeapAccess.Access.NO_ALLOCATION, reason = "Must not allocate while verifying the stack.")
public boolean visitRegularFrame(Pointer currentSP, CodePointer currentIP, CodeInfo codeInfo) {
verifyFrameReferencesVisitor.initialize();
verifyFrameReferencesVisitor.initialize(currentSP, currentIP);
CodeInfoTable.visitObjectReferences(currentSP, currentIP, codeInfo, verifyFrameReferencesVisitor);
result &= verifyFrameReferencesVisitor.result;
return true;
Expand All @@ -103,29 +103,44 @@ protected boolean visitDeoptimizedFrame(Pointer originalSP, CodePointer deoptStu
}
}

private static class VerifyFrameReferencesVisitor implements ObjectReferenceVisitor {
public static class VerifyFrameReferencesVisitor implements ObjectReferenceVisitor {
private Pointer sp;
private CodePointer ip;
private boolean result;

@Platforms(Platform.HOSTED_ONLY.class)
VerifyFrameReferencesVisitor() {
}

public void initialize() {
@SuppressWarnings("hiding")
public void initialize(Pointer sp, CodePointer ip) {
this.sp = sp;
this.ip = ip;
this.result = true;
}

public Pointer getSP() {
return sp;
}

public CodePointer getIP() {
return ip;
}

@Override
public void visitObjectReferences(Pointer firstObjRef, boolean compressed, int referenceSize, Object holderObject, int count) {
assert holderObject == null;

Pointer pos = firstObjRef;
Pointer end = firstObjRef.add(Word.unsigned(count).multiply(referenceSize));
while (pos.belowThan(end)) {
visitObjectReference(pos, compressed, holderObject);
visitObjectReference(pos, compressed);
pos = pos.add(referenceSize);
}
}

private void visitObjectReference(Pointer objRef, boolean compressed, Object holderObject) {
result &= HeapVerifier.verifyReference(holderObject, objRef, compressed);
private void visitObjectReference(Pointer objRef, boolean compressed) {
result &= HeapVerifier.verifyReference(this, objRef, compressed);
}
}
}