Skip to content

Commit fd33d62

Browse files
committed
Invoke teardown hooks in Shutdown#exit substitution
1 parent e5da13a commit fd33d62

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_Shutdown.java

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
package com.oracle.svm.core.jdk;
2626

2727
import com.oracle.svm.core.annotate.Alias;
28+
import com.oracle.svm.core.annotate.Delete;
2829
import com.oracle.svm.core.annotate.RecomputeFieldValue;
2930
import com.oracle.svm.core.annotate.Substitute;
3031
import com.oracle.svm.core.annotate.TargetClass;
31-
import com.oracle.svm.core.annotate.TargetElement;
3232
import com.oracle.svm.core.util.VMError;
3333

3434
@TargetClass(className = "java.lang.Shutdown")
@@ -45,23 +45,41 @@ public final class Target_java_lang_Shutdown {
4545
hooks[Util_java_lang_Shutdown.NATIVE_IMAGE_SHUTDOWN_HOOKS_SLOT] = RuntimeSupport::executeShutdownHooks;
4646
}
4747

48-
@Substitute
49-
static void beforeHalt() {
50-
}
51-
5248
/**
5349
* Invoked by the JNI DestroyJavaVM procedure when the last non-daemon thread has finished.
5450
* Unlike the exit method, this method does not actually halt the VM.
5551
*/
5652
@Alias
5753
static native void shutdown();
5854

55+
@Delete
56+
private static native void logRuntimeExit(int status);
57+
58+
@Delete
59+
static native void beforeHalt();
60+
61+
/**
62+
* This substitution makes a few modifications to {@code Shutdown#exit}:
63+
* <ul>
64+
* <li>it omits {@code logRuntimeExit} (exit logging is disabled: GR-45418/JDK-8301627).</li>
65+
* <li>it omits {@code beforeHalt} (not implemented).</li>
66+
* <li>it runs teardown hooks after running shutdown hooks and before halting.</li>
67+
* </ul>
68+
*/
5969
@Substitute
60-
@TargetElement
61-
@SuppressWarnings("unused")
62-
private static void logRuntimeExit(int status) {
63-
// Disable exit logging (GR-45418/JDK-8301627)
70+
static void exit(int status) {
71+
synchronized (Target_java_lang_Shutdown.class) {
72+
runHooks();
73+
RuntimeSupport.executeTearDownHooks();
74+
halt(status);
75+
}
6476
}
77+
78+
@Alias
79+
static native void runHooks();
80+
81+
@Alias
82+
static native void halt(int status);
6583
}
6684

6785
/** Utility methods for Target_java_lang_Shutdown. */

0 commit comments

Comments
 (0)