Skip to content

Commit

Permalink
Add crash log output to exception handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
christianhaeubl committed Dec 15, 2023
1 parent 1bce1dd commit 80332b8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.Isolate;
import org.graalvm.nativeimage.IsolateThread;
import org.graalvm.nativeimage.LogHandler;
import org.graalvm.nativeimage.StackValue;
import org.graalvm.nativeimage.c.type.CCharPointer;
import org.graalvm.nativeimage.c.type.CLongPointer;
Expand Down Expand Up @@ -716,13 +715,14 @@ private static int reportException(Throwable exception) {

private static void reportExceptionInterruptibly(Throwable exception) {
logException(exception);
ImageSingletons.lookup(LogHandler.class).fatalError();
VMError.shouldNotReachHere("Unhandled exception");
}

@RestrictHeapAccess(access = NO_ALLOCATION, reason = "Must not allocate in fatal error handling.")
private static void logException(Throwable exception) {
try {
Log.log().exception(exception).newline();
Log.log().string("Unhandled exception: ");
Log.log().exception(exception).newline().newline();
} catch (Throwable ex) {
/* Logging failed, so there is nothing we can do anymore to log. */
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

import org.graalvm.nativeimage.CurrentIsolate;
import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.LogHandler;
import org.graalvm.nativeimage.StackValue;
import org.graalvm.nativeimage.c.function.CodePointer;
import org.graalvm.nativeimage.hosted.Feature;
Expand Down Expand Up @@ -57,6 +56,7 @@
import com.oracle.svm.core.thread.VMThreads;
import com.oracle.svm.core.threadlocal.FastThreadLocalFactory;
import com.oracle.svm.core.threadlocal.FastThreadLocalObject;
import com.oracle.svm.core.util.VMError;

public abstract class ExceptionUnwind {

Expand Down Expand Up @@ -145,8 +145,8 @@ private static void unwindExceptionInterruptible(Throwable exception, Pointer ca
*/
private static void reportRecursiveUnwind(Throwable exception) {
Log.log().string("Fatal error: recursion in exception handling: ").string(exception.getClass().getName());
Log.log().string(" thrown while unwinding ").string(currentException.get().getClass().getName()).newline();
ImageSingletons.lookup(LogHandler.class).fatalError();
Log.log().string(" thrown while unwinding ").string(currentException.get().getClass().getName()).newline().newline();
VMError.shouldNotReachHere("Recursion in exception handling");
}

/**
Expand All @@ -159,8 +159,8 @@ private static void reportRecursiveUnwind(Throwable exception) {
*/
private static void reportFatalUnwind(Throwable exception) {
Log.log().string("Fatal error: exception unwind while thread is not in Java state: ");
Log.log().exception(exception).newline();
ImageSingletons.lookup(LogHandler.class).fatalError();
Log.log().exception(exception).newline().newline();
VMError.shouldNotReachHere("Exception unwind while thread is not in Java state");
}

/**
Expand All @@ -171,8 +171,8 @@ private static void reportFatalUnwind(Throwable exception) {
*/
private static void reportUnhandledException(Throwable exception) {
Log.log().string("Fatal error: unhandled exception in isolate ").hex(CurrentIsolate.getIsolate()).string(": ");
Log.log().exception(exception).newline();
ImageSingletons.lookup(LogHandler.class).fatalError();
Log.log().exception(exception).newline().newline();
VMError.shouldNotReachHere("Unhandled exception");
}

/** Hook to allow a {@link Feature} to install custom exception unwind code. */
Expand Down

0 comments on commit 80332b8

Please sign in to comment.