diff --git a/src/hotspot/share/prims/whitebox.cpp b/src/hotspot/share/prims/whitebox.cpp index 9beb50fe78b..aaaac349ee3 100644 --- a/src/hotspot/share/prims/whitebox.cpp +++ b/src/hotspot/share/prims/whitebox.cpp @@ -102,6 +102,7 @@ #include "utilities/macros.hpp" #include "utilities/nativeCallStack.hpp" #include "utilities/ostream.hpp" +#include "utilities/vmError.hpp" #if INCLUDE_G1GC #include "gc/g1/g1Arguments.hpp" #include "gc/g1/g1CollectedHeap.inline.hpp" @@ -2728,6 +2729,14 @@ WB_ENTRY(jlong, WB_Rss(JNIEnv* env, jobject o)) return os::rss(); WB_END +WB_ENTRY(void, WB_ControlledCrash(JNIEnv* env, jobject o, jint how)) +#ifdef ASSERT + VMError::controlled_crash(how); +#else + THROW_MSG(vmSymbols::java_lang_UnsupportedOperationException(), "Only available in debug builds"); +#endif +WB_END + #define CC (char*) static JNINativeMethod methods[] = { @@ -3019,10 +3028,10 @@ static JNINativeMethod methods[] = { {CC"lockAndStuckInSafepoint", CC"()V", (void*)&WB_TakeLockAndHangInSafepoint}, {CC"wordSize", CC"()J", (void*)&WB_WordSize}, {CC"rootChunkWordSize", CC"()J", (void*)&WB_RootChunkWordSize}, - {CC"isStatic", CC"()Z", (void*)&WB_IsStaticallyLinked} + {CC"isStatic", CC"()Z", (void*)&WB_IsStaticallyLinked}, + {CC"controlledCrash",CC"(I)V", (void*)&WB_ControlledCrash}, }; - #undef CC JVM_ENTRY(void, JVM_RegisterWhiteBoxMethods(JNIEnv* env, jclass wbclass)) diff --git a/test/hotspot/jtreg/runtime/ErrorHandling/ShowEventsOnCrashTest.java b/test/hotspot/jtreg/runtime/ErrorHandling/ShowEventsOnCrashTest.java index 0c8646a4345..d0660d61894 100644 --- a/test/hotspot/jtreg/runtime/ErrorHandling/ShowEventsOnCrashTest.java +++ b/test/hotspot/jtreg/runtime/ErrorHandling/ShowEventsOnCrashTest.java @@ -30,11 +30,15 @@ * @requires vm.flagless * @requires vm.debug == true & (os.family == "linux" | os.family == "windows") * @modules java.base/jdk.internal.misc + * @build jdk.test.whitebox.WhiteBox + * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox * @run driver ShowEventsOnCrashTest */ // Note: this test can only run on debug since it relies on VMError::controlled_crash() which // only exists in debug builds. + +import jdk.test.whitebox.WhiteBox; import java.io.File; import java.util.regex.Pattern; @@ -45,10 +49,17 @@ public class ShowEventsOnCrashTest { public static void main(String[] args) throws Exception { + if (args.length > 0 && args[0].equals("test")) { + Thread.sleep(2000); // Wait to accumulate log entries + WhiteBox.getWhiteBox().controlledCrash(2); + throw new RuntimeException("Still alive?"); + } + ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder( - "-XX:+UnlockDiagnosticVMOptions", "-Xmx100M", "-XX:-CreateCoredumpOnCrash", - "-XX:ErrorHandlerTest=2", - "-version"); + "-Xbootclasspath/a:.", + "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI", + "-Xmx100M", "-XX:-CreateCoredumpOnCrash", + ShowEventsOnCrashTest.class.getName(), "test"); OutputAnalyzer output_detail = new OutputAnalyzer(pb.start()); diff --git a/test/lib/jdk/test/whitebox/WhiteBox.java b/test/lib/jdk/test/whitebox/WhiteBox.java index f3d9ba7b6e9..ce8b61b6393 100644 --- a/test/lib/jdk/test/whitebox/WhiteBox.java +++ b/test/lib/jdk/test/whitebox/WhiteBox.java @@ -851,4 +851,7 @@ public class WhiteBox { public native long rss(); public native boolean isStatic(); + + // Force a controlled crash (debug builds only) + public native void controlledCrash(int how); }