Skip to content

Commit 807f516

Browse files
author
Christian Wimmer
committed
[GR-10068] Add more diagnostics for crashes.
PullRequest: graal/1821
2 parents 2ef424b + e761864 commit 807f516

File tree

3 files changed

+51
-7
lines changed

3 files changed

+51
-7
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/MonitorSupport.java

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

3434
import org.graalvm.compiler.core.common.SuppressFBWarnings;
3535
import org.graalvm.compiler.word.BarrieredAccess;
36+
import org.graalvm.compiler.word.Word;
3637
import org.graalvm.nativeimage.Feature;
3738
import org.graalvm.nativeimage.ImageSingletons;
3839

@@ -98,8 +99,10 @@ public static void monitorEnter(Object obj) {
9899
return;
99100
}
100101

102+
ReentrantLock lockObject = null;
101103
try {
102-
ImageSingletons.lookup(MonitorSupport.class).getOrCreateMonitor(obj, true).lock();
104+
lockObject = ImageSingletons.lookup(MonitorSupport.class).getOrCreateMonitor(obj, true);
105+
lockObject.lock();
103106
} catch (Throwable ex) {
104107
/*
105108
* The foreign call from snippets to this method does not have an exception edge. So we
@@ -112,7 +115,7 @@ public static void monitorEnter(Object obj) {
112115
* Finally, it would not be clear whether the monitor is locked or unlocked in case of
113116
* an exception.
114117
*/
115-
VMError.shouldNotReachHere(ex);
118+
throw shouldNotReachHere("monitorEnter", obj, lockObject, ex);
116119
}
117120
}
118121

@@ -130,8 +133,10 @@ public static void monitorExit(Object obj) {
130133
return;
131134
}
132135

136+
ReentrantLock lockObject = null;
133137
try {
134-
ImageSingletons.lookup(MonitorSupport.class).getOrCreateMonitor(obj, true).unlock();
138+
lockObject = ImageSingletons.lookup(MonitorSupport.class).getOrCreateMonitor(obj, true);
139+
lockObject.unlock();
135140
} catch (Throwable ex) {
136141
/*
137142
* The foreign call from snippets to this method does not have an exception edge. So we
@@ -141,10 +146,46 @@ public static void monitorExit(Object obj) {
141146
* the Java Virtual Machine Specification, but it ensures that we never need to throw an
142147
* IllegalMonitorStateException.
143148
*/
144-
VMError.shouldNotReachHere(ex);
149+
throw shouldNotReachHere("monitorExit", obj, lockObject, ex);
145150
}
146151
}
147152

153+
private static RuntimeException shouldNotReachHere(String label, Object obj, ReentrantLock lockObject, Throwable ex) {
154+
StringBuilder msg = new StringBuilder();
155+
msg.append("Unexpected exception in MonitorSupport.").append(label);
156+
157+
if (obj != null) {
158+
msg.append(" object: ");
159+
appendObject(msg, obj);
160+
}
161+
if (lockObject != null) {
162+
msg.append(" lock: ");
163+
appendObject(msg, lockObject);
164+
165+
Target_java_util_concurrent_locks_ReentrantLock lockObjectTarget = KnownIntrinsics.unsafeCast(lockObject, Target_java_util_concurrent_locks_ReentrantLock.class);
166+
Target_java_util_concurrent_locks_AbstractOwnableSynchronizer sync = KnownIntrinsics.unsafeCast(lockObjectTarget.sync, Target_java_util_concurrent_locks_AbstractOwnableSynchronizer.class);
167+
168+
if (sync != null) {
169+
msg.append(" sync: ");
170+
appendObject(msg, sync);
171+
172+
Thread thread = sync.getExclusiveOwnerThread();
173+
if (thread == null) {
174+
msg.append(" no exclusiveOwnerThread");
175+
} else {
176+
msg.append(" exclusiveOwnerThread: ");
177+
appendObject(msg, thread);
178+
}
179+
}
180+
}
181+
msg.append(" raw exception: ");
182+
throw VMError.shouldNotReachHere(msg.toString(), ex);
183+
}
184+
185+
private static void appendObject(StringBuilder msg, Object obj) {
186+
msg.append(obj.getClass().getName()).append("@").append(Long.toHexString(Word.objectToUntrackedPointer(obj).rawValue()));
187+
}
188+
148189
/**
149190
* This is a highly unsafe method that patches the existing lock of an object so that the object
150191
* appears as if it has been locked from a different thread. It is only safe to call when the

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateUtil.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
import com.oracle.svm.core.stack.JavaStackWalker;
6868
import com.oracle.svm.core.stack.StackFrameVisitor;
6969
import com.oracle.svm.core.stack.ThreadStackPrinter;
70+
import com.oracle.svm.core.thread.JavaThreads;
7071
import com.oracle.svm.core.thread.VMOperationControl;
7172
import com.oracle.svm.core.thread.VMThreads;
7273
import com.oracle.svm.core.threadlocal.VMThreadLocalInfos;
@@ -379,7 +380,8 @@ private static void dumpVMThreads(Log log) {
379380
log.string("VMThreads info:").newline();
380381
log.indent(true);
381382
for (IsolateThread vmThread = VMThreads.firstThread(); vmThread != VMThreads.nullThread(); vmThread = VMThreads.nextThread(vmThread)) {
382-
log.string("VMThread ").zhex(vmThread.rawValue()).spaces(2).string(VMThreads.StatusSupport.getStatusString(vmThread)).newline();
383+
log.string("VMThread ").zhex(vmThread.rawValue()).spaces(2).string(VMThreads.StatusSupport.getStatusString(vmThread))
384+
.spaces(2).object(JavaThreads.singleton().fromVMThread(vmThread)).newline();
383385
}
384386
log.indent(false);
385387
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/deopt/Deoptimizer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ private static void printDeoptimizedFrame(Log log, Pointer sp, DeoptimizedFrame
10231023
}
10241024
log.string(" return address ").hex(targetFrame.returnAddress.returnAddress).newline();
10251025

1026-
if (Options.TraceDeoptimizationDetails.getValue()) {
1026+
if (printOnlyTopFrames || Options.TraceDeoptimizationDetails.getValue()) {
10271027
printVirtualFrame(log, targetFrame);
10281028
}
10291029

@@ -1050,7 +1050,7 @@ private static void printVirtualFrame(Log log, VirtualFrame virtualFrame) {
10501050
log.string(" bci: ").signed(frameInfo.getBci());
10511051
log.string(" deoptMethodOffset: ").signed(frameInfo.getDeoptMethodOffset());
10521052
log.string(" deoptMethod: ").hex(frameInfo.getDeoptMethodAddress());
1053-
log.string(" return address: ").hex(virtualFrame.returnAddress.returnAddress);
1053+
log.string(" return address: ").hex(virtualFrame.returnAddress.returnAddress).string(" offset: ").signed(virtualFrame.returnAddress.offset);
10541054

10551055
for (int i = 0; i < frameInfo.getValueInfos().length; i++) {
10561056
JavaConstant con = virtualFrame.getConstant(i);
@@ -1071,6 +1071,7 @@ private static void printVirtualFrame(Log log, VirtualFrame virtualFrame) {
10711071
} else {
10721072
log.string(" value: ").string(con.toValueString());
10731073
}
1074+
log.string(" offset: ").signed(virtualFrame.values[i].offset);
10741075
}
10751076
}
10761077
log.newline();

0 commit comments

Comments
 (0)