-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JBR-7600 Provide ability to add messages to fatal error log
Use JNU_LOG_EVENT(env, msg, ...) to save a message in the internal JVM ring buffer that gets printed out to the Events section of the fatal error log if JVM crashed.
- Loading branch information
1 parent
37a074e
commit 31a2128
Showing
8 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright 2024 JetBrains s.r.o. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
/** | ||
* @test | ||
* @summary Verifies the error log does contain events previously | ||
* logged with JNU_LOG_EVENT() | ||
* @library /test/lib | ||
* @run main/native LogEventTest | ||
*/ | ||
|
||
import jdk.test.lib.Platform; | ||
import jdk.test.lib.process.ProcessTools; | ||
import jdk.test.lib.process.OutputAnalyzer; | ||
|
||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.ArrayList; | ||
|
||
public class LogEventTest { | ||
|
||
public static void main(String args[]) throws Exception { | ||
if (args.length > 0 && args[0].equals("--test")) { | ||
System.out.println("Proceeding to crash JVM with a simulated assertion failure"); | ||
String osDependentLibraryFileName = toPlatformLibraryName("LogEventTest"); | ||
String nativePathName = System.getProperty("test.nativepath"); | ||
Path nativePath = Paths.get(nativePathName).resolve(osDependentLibraryFileName); | ||
System.out.println("Loading library from: " + nativePath); | ||
System.load(String.valueOf(nativePath)); | ||
logEvent(42); | ||
crashJVM(); | ||
System.out.println("...shouldn't reach here"); | ||
} else { | ||
generateAndVerifyCrashLogContents(); | ||
} | ||
} | ||
|
||
public static void generateAndVerifyCrashLogContents() throws Exception { | ||
String nativePathSetting = "-Dtest.nativepath=" + System.getProperty("test.nativepath"); | ||
ArrayList<String> opts = new ArrayList<>(); | ||
opts.add("-XX:-CreateCoredumpOnCrash"); | ||
opts.add("-XX:+ErrorFileToStdout"); | ||
opts.add("--enable-native-access=ALL-UNNAMED"); | ||
opts.add(nativePathSetting); | ||
opts.add(LogEventTest.class.getName()); | ||
opts.add("--test"); | ||
ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(opts); | ||
OutputAnalyzer output = new OutputAnalyzer(pb.start()); | ||
output.outputTo(System.out); | ||
output.shouldContain("LogEventTest: unique log message"); | ||
output.shouldContain("LogEventTest: 42"); | ||
} | ||
|
||
private static String toPlatformLibraryName(String name) { | ||
return (Platform.isWindows() ? "" : "lib") + name + "." + Platform.sharedLibraryExt(); | ||
} | ||
|
||
static native void logEvent(int arg); | ||
static native void crashJVM(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2024 JetBrains s.r.o. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
#include <jni_util.h> | ||
|
||
JNIEXPORT void JNICALL | ||
Java_LogEventTest_logEvent(JNIEnv* env, jclass cls, jint arg) { | ||
JNU_LOG_EVENT(env, "LogEventTest: unique log message"); | ||
JNU_LOG_EVENT(env, "LogEventTest: %d", arg); | ||
} | ||
|
||
JNIEXPORT void JNICALL | ||
Java_LogEventTest_crashJVM(JNIEnv* env, jclass cls) { | ||
JNU_RUNTIME_ASSERT(env, 0 == 1, "Java_LogEventTest_crashJVM: unique message"); | ||
} |