Home >Java >How to make the JVM exit quickly after a SIGSEGV crash?

How to make the JVM exit quickly after a SIGSEGV crash?

WBOY
WBOYforward
2024-02-09 19:09:091097browse

php editor Xigua will give you the answer. When the JVM encounters a SIGSEGV crash, you can take some measures to exit quickly. First, you can set the JVM parameter -XX: CrashOnOutOfMemoryError to cause the JVM to crash and exit quickly when memory overflows. Secondly, you can use Java's exception handling mechanism to catch SIGSEGV exceptions, and call the System.exit() method to exit the program after catching the exception. In addition, you can also use the JNI interface to interact with the operating system and achieve quick exit by calling the exit method provided by the operating system. In short, by properly setting JVM parameters and using appropriate exception handling mechanisms, the JVM can quickly exit after a SIGSEGV crash and improve the stability and reliability of the program.

Question content

One of our services crashes frequently due to some issues with tensorflow java. We can live with that (k8s will restart it, many instances). The problem is that the jvm takes several minutes to terminate. Is there a way to force a fast exit of sigsegv in native code?

corrupted size vs. prev_size while consolidating
#
# a fatal error has been detected by the java runtime environment:
#
#  sigsegv (0xb) at pc=0x00007fe4f321a898, pid=1, tid=545
#
# jre version: openjdk runtime environment zulu21.28+85-ca (21.0+35) (build 21+35)
# java vm: openjdk 64-bit server vm zulu21.28+85-ca (21+35, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, linux-amd64)
# problematic frame:
# c  [libc.so.6+0x28898]  abort+0x178
#
# core dump will be written. default location: /data/core
#
# an error report file with more information is saved as:
# /data/hs_err_pid1.log

A few minutes later:

# [ timer expired, abort... ]
[thread 1037 also had an error]

Solution

Add the following jvm options:

-xx:+suppressfatalerrormessage -xx:-createcoredumponcrash

This will force the jvm to terminate immediately on sigsegv without creating an error report or core dump. If you still want to see fatal error messages, replace -xx: suppressfatalerrormessage with -xx:errorlogtimeout=1.

I suspect this jvm is running with a fairly large heap (> 64 gb), and for a process using so much memory, writing out the core dump file just takes a while:

# Core dump will be written. Default location: /data/core

During the few minutes this takes, you may see the core dump file growing at the above location (this would be an easy way to confirm this theory).

The remedy is to disable the creation of core dump files, the details of which depend on your specific operating system (but core dumps can be disabled on almost any unix-based operating system). Additionally, there may be some filesystem-related bottlenecks at that particular location, causing the core dump to be written slower than expected.

The above is the detailed content of How to make the JVM exit quickly after a SIGSEGV crash?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete
Previous article:Update AWS credentialsNext article:Update AWS credentials