Skip to content

Commit b991b1d

Browse files
[GR-69694] Fix stack walking of crashed threads.
PullRequest: graal/22147
2 parents 098eaa3 + f44066a commit b991b1d

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/locks/VMMutex.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
*/
2525
package com.oracle.svm.core.locks;
2626

27-
import jdk.graal.compiler.word.Word;
2827
import org.graalvm.nativeimage.CurrentIsolate;
2928
import org.graalvm.nativeimage.IsolateThread;
3029
import org.graalvm.nativeimage.Platform;
@@ -35,6 +34,8 @@
3534
import com.oracle.svm.core.c.CIsolateDataFactory;
3635
import com.oracle.svm.core.util.VMError;
3736

37+
import jdk.graal.compiler.word.Word;
38+
3839
/**
3940
* A mutex that has minimal requirements on Java code. The implementation does not perform memory
4041
* allocation, exception unwinding, or other complicated operations. This allows it to be used in
@@ -56,6 +57,7 @@ public class VMMutex extends VMLockingPrimitive {
5657
private final String name;
5758
IsolateThread owner;
5859

60+
@Deprecated
5961
@Platforms(Platform.HOSTED_ONLY.class)
6062
public VMMutex() {
6163
this.name = CIsolateDataFactory.getUnspecifiedSuffix();

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/stack/JavaStackWalker.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626

2727
import static com.oracle.svm.core.Uninterruptible.CALLED_FROM_UNINTERRUPTIBLE_CODE;
2828

29-
import com.oracle.svm.core.deopt.DeoptimizationSlotPacking;
30-
import jdk.graal.compiler.word.Word;
3129
import org.graalvm.nativeimage.CurrentIsolate;
3230
import org.graalvm.nativeimage.IsolateThread;
3331
import org.graalvm.nativeimage.Platform;
@@ -46,6 +44,7 @@
4644
import com.oracle.svm.core.code.CodeInfoTable;
4745
import com.oracle.svm.core.code.UntetheredCodeInfo;
4846
import com.oracle.svm.core.config.ConfigurationValues;
47+
import com.oracle.svm.core.deopt.DeoptimizationSlotPacking;
4948
import com.oracle.svm.core.deopt.DeoptimizedFrame;
5049
import com.oracle.svm.core.deopt.Deoptimizer;
5150
import com.oracle.svm.core.heap.RestrictHeapAccess;
@@ -61,6 +60,7 @@
6160

6261
import jdk.graal.compiler.api.replacements.Fold;
6362
import jdk.graal.compiler.core.common.NumUtil;
63+
import jdk.graal.compiler.word.Word;
6464

6565
/**
6666
* Provides methods to iterate over the physical Java stack frames of a thread (native stack frames
@@ -203,14 +203,24 @@ public static void initializeForContinuation(JavaStackWalk walk, StoredContinuat
203203

204204
@Uninterruptible(reason = "Prevent deoptimization of stack frames while in this method.", callerMustBe = true)
205205
private static void initializeFromFrameAnchor(JavaStackWalk walk, IsolateThread thread, Pointer endSP) {
206+
assert thread.isNonNull();
206207
assert thread != CurrentIsolate.getCurrentThread() : "Walking the stack without specifying a start SP is only allowed when walking other threads";
208+
assert VMOperation.isInProgressAtSafepoint() : "Walking the stack of another thread is only safe when that thread is stopped at a safepoint";
207209

208210
JavaFrameAnchor frameAnchor = JavaFrameAnchors.getFrameAnchor(thread);
209-
if (frameAnchor.isNull()) {
210-
/* Threads that do not have a frame anchor at a safepoint are not walkable. */
211+
if (frameAnchor.isNull() || SafepointBehavior.isCrashedThread(thread)) {
212+
/*
213+
* Threads that do not have a frame anchor at a safepoint are not walkable. This can for
214+
* example happen for attached threads that do not have any Java frames at the moment.
215+
* Threads that are marked as crashed are also not walkable because they may no longer
216+
* have a stack. For such threads, we must not access any data in the frame anchor (as
217+
* it is a stack allocated struct).
218+
*/
211219
markAsNotWalkable(walk);
212220
} else {
213-
initWalk(walk, thread, frameAnchor.getLastJavaSP(), endSP, frameAnchor.getLastJavaIP(), frameAnchor.getPreviousAnchor());
221+
Pointer startSP = frameAnchor.getLastJavaSP();
222+
assert startSP.isNonNull();
223+
initWalk0(walk, startSP, endSP, frameAnchor.getLastJavaIP(), frameAnchor.getPreviousAnchor());
214224
}
215225
}
216226

0 commit comments

Comments
 (0)