Skip to content

Commit 9fcc190

Browse files
[GR-67673] Report more information if the heap verification finds a broken reference on the stack.
PullRequest: graal/21493
2 parents 5956cf6 + 7b247bb commit 9fcc190

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
import com.oracle.svm.core.config.ConfigurationValues;
3535
import com.oracle.svm.core.genscavenge.AlignedHeapChunk.AlignedHeader;
36+
import com.oracle.svm.core.genscavenge.StackVerifier.VerifyFrameReferencesVisitor;
3637
import com.oracle.svm.core.genscavenge.UnalignedHeapChunk.UnalignedHeader;
3738
import com.oracle.svm.core.genscavenge.remset.RememberedSet;
3839
import com.oracle.svm.core.heap.Heap;
@@ -384,10 +385,11 @@ private static boolean verifyReference(Object parentObject, Pointer reference, P
384385
}
385386

386387
private static void printParent(Object parentObject) {
387-
if (parentObject != null) {
388-
Log.log().string("The object that contains the invalid reference is of type ").string(parentObject.getClass().getName()).newline();
388+
if (parentObject instanceof VerifyFrameReferencesVisitor visitor) {
389+
Log.log().string("The invalid reference is on the stack: sp=").zhex(visitor.getSP()).string(", ip=").zhex(visitor.getIP()).newline();
389390
} else {
390-
Log.log().string("The invalid reference is on the stack").newline();
391+
assert parentObject != null;
392+
Log.log().string("The object that contains the invalid reference is of type ").string(parentObject.getClass().getName()).newline();
391393
}
392394
}
393395

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

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void initialize() {
8989
@Override
9090
@RestrictHeapAccess(access = RestrictHeapAccess.Access.NO_ALLOCATION, reason = "Must not allocate while verifying the stack.")
9191
public boolean visitRegularFrame(Pointer currentSP, CodePointer currentIP, CodeInfo codeInfo) {
92-
verifyFrameReferencesVisitor.initialize();
92+
verifyFrameReferencesVisitor.initialize(currentSP, currentIP);
9393
CodeInfoTable.visitObjectReferences(currentSP, currentIP, codeInfo, verifyFrameReferencesVisitor);
9494
result &= verifyFrameReferencesVisitor.result;
9595
return true;
@@ -103,29 +103,44 @@ protected boolean visitDeoptimizedFrame(Pointer originalSP, CodePointer deoptStu
103103
}
104104
}
105105

106-
private static class VerifyFrameReferencesVisitor implements ObjectReferenceVisitor {
106+
public static class VerifyFrameReferencesVisitor implements ObjectReferenceVisitor {
107+
private Pointer sp;
108+
private CodePointer ip;
107109
private boolean result;
108110

109111
@Platforms(Platform.HOSTED_ONLY.class)
110112
VerifyFrameReferencesVisitor() {
111113
}
112114

113-
public void initialize() {
115+
@SuppressWarnings("hiding")
116+
public void initialize(Pointer sp, CodePointer ip) {
117+
this.sp = sp;
118+
this.ip = ip;
114119
this.result = true;
115120
}
116121

122+
public Pointer getSP() {
123+
return sp;
124+
}
125+
126+
public CodePointer getIP() {
127+
return ip;
128+
}
129+
117130
@Override
118131
public void visitObjectReferences(Pointer firstObjRef, boolean compressed, int referenceSize, Object holderObject, int count) {
132+
assert holderObject == null;
133+
119134
Pointer pos = firstObjRef;
120135
Pointer end = firstObjRef.add(Word.unsigned(count).multiply(referenceSize));
121136
while (pos.belowThan(end)) {
122-
visitObjectReference(pos, compressed, holderObject);
137+
visitObjectReference(pos, compressed);
123138
pos = pos.add(referenceSize);
124139
}
125140
}
126141

127-
private void visitObjectReference(Pointer objRef, boolean compressed, Object holderObject) {
128-
result &= HeapVerifier.verifyReference(holderObject, objRef, compressed);
142+
private void visitObjectReference(Pointer objRef, boolean compressed) {
143+
result &= HeapVerifier.verifyReference(this, objRef, compressed);
129144
}
130145
}
131146
}

0 commit comments

Comments
 (0)