当前位置:网站首页>Meituan side: why does thread crash not cause JVM crash
Meituan side: why does thread crash not cause JVM crash
2022-07-03 16:46:00 【InfoQ】

- Thread crash , Is the process bound to crash
- How the process crashed - Introduction to signaling mechanism
- Why is it JVM Thread crash in does not cause JVM Process breakdown
- openJDK The source code parsing
Thread crash , Is the process bound to crash ?

- Write data to read-only memory
- #include <stdio.h> #include <stdlib.h> int main() { char *s = "hello world";// Write data to read-only memory , collapse s[1] = 'H'; }
- Accessed the address space that the process does not have permission to access ( Such as kernel space )
- #include <stdio.h> #include <stdlib.h> int main() { int *p = (int *)0xC0000fff; // Write data to the kernel space of the process , collapse *p = 10; }
- stay 32 Bit virtual address space ,p It points to kernel space , Obviously do not have write permission , Therefore, the above assignment operation will cause a crash
- Accessed nonexistent memory , such as
- #include <stdio.h> #include <stdlib.h> int main() { int *a = NULL; *a = 1; }
How the process crashed - Introduction to signaling mechanism

- CPU Execute normal process instructions
- call kill System calls send signals to processes
- The process receives a signal from the operating system ,CPU Pause the current program , And transfer control to the operating system
- call kill System calls send signals to processes ( Assuming that 11, namely SIGSEGV, This error is usually reported for illegal access to memory )
- The operating system executes the corresponding signal processing program according to the situation ( function ), Generally, the process will exit after the signal handler logic is executed
// Examples of custom signal processing functions
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
// Custom signal processing functions , Call... After processing the custom logic exit sign out
void sigHandler(int sig) {
printf("Signal %d catched!\n", sig);
exit(sig);
}
int main(void) {
signal(SIGSEGV, sigHandler);
int *p = (int *)0xC0000fff;
*p = 10; // Write data to kernel space that does not belong to a process , collapse
}
// The above results output : Signal 11 catched!#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
int main(void) {
// Ignore the signal
signal(SIGSEGV, SIG_IGN);
// Produce a SIGSEGV The signal
raise(SIGSEGV);
printf(" Normal end ");
}Why thread crashes don't cause JVM Process breakdown


openJDK The source code parsing

JVM_handle_linux_signal(int sig,
siginfo_t* info,
void* ucVoid,
int abort_if_unrecognized) {
// Must do this before SignalHandlerMark, if crash protection installed we will longjmp away
// This code calls siglongjmp, Mainly used for thread recovery
os::ThreadCrashProtection::check_crash_protection(sig, t);
if (info != NULL && uc != NULL && thread != NULL) {
pc = (address) os::Linux::ucontext_get_pc(uc);
// Handle ALL stack overflow variations here
if (sig == SIGSEGV) {
// Si_addr may not be valid due to a bug in the linux-ppc64 kernel (see
// comment below). Use get_stack_bang_address instead of si_addr.
address addr = ((NativeInstruction*)pc)->get_stack_bang_address(uc);
// Determine whether the stack overflows
if (addr < thread->stack_base() &&
addr >= thread->stack_base() - thread->stack_size()) {
if (thread->thread_state() == _thread_in_Java) {
// For stack overflow JVM Internal treatment of
stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW);
}
}
}
}
if (sig == SIGSEGV &&
!MacroAssembler::needs_explicit_null_check((intptr_t)info->si_addr)) {
// Null pointer check will be performed here
stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
}
// If it is a stack overflow or a null pointer, it will eventually return true, Will not take the last report_and_die, therefore JVM Will not quit
if (stub != NULL) {
// save all thread context in case we need to restore it
if (thread != NULL) thread->set_saved_exception_pc(pc);
uc->uc_mcontext.gregs[REG_PC] = (greg_t)stub;
// return true representative JVM The process does not exit
return true;
}
VMError err(t, sig, pc, info, ucVoid);
// Generate hs_err_pid_xxx.log File and exit
err.report_and_die();
ShouldNotReachHere();
return true; // Mute compiler
}- happen stackoverflow And null pointer errors , They were all sent SIGSEGV, Only the virtual machine does not choose to exit , It's an extra internal process , In fact, it is the process that restores the thread , And throw StackoverflowError and NPE, That's why JVM Will not crash and we can catch these two errors / The cause of the abnormality
- If it is aimed at SIGSEGV Equal signal , In the above function JVM No extra processing , Then we will finally come to report_and_die This method , The main thing this method does is generate hs_err_pid_xxx.log crash file ( Some stack information or errors are logged ), And then quit
summary
边栏推荐
- 數據分析必備的能力
- NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
- What material is sa537cl2 equivalent to in China? Sa537cl2 corresponding material
- Extraction of the same pointcut
- mysql用户管理
- Hong Kong Polytechnic University | data efficient reinforcement learning and adaptive optimal perimeter control of network traffic dynamics
- What material is 12cr1movr? Chemical property analysis of pressure vessel steel plate 12cr1movr
- 13mnnimo5-4 German standard steel plate 13MnNiMo54 boiler steel 13MnNiMo54 chemical properties
- CC2530 common registers for port initialization
- JSON 与 BSON 区别
猜你喜欢

Le zèbre a été identifié comme un chien, et la cause de l'erreur d'AI a été trouvée par Stanford

网络安全web渗透技术

Idea configuration plug-in

斑马识别成狗,AI犯错的原因被斯坦福找到了

Cocos Creator 2.x 自动打包(构建 + 编译)
![[solved] access denied for user 'root' @ 'localhost' (using password: yes)](/img/71/1ff8ed1d773da99054310f96dca3f8.jpg)
[solved] access denied for user 'root' @ 'localhost' (using password: yes)

What material is sa537cl2? Analysis of mechanical properties of American standard container plate

What is the maximum number of concurrent TCP connections for a server? 65535?

TCP congestion control details | 3 design space

2022 love analysis · panoramic report of digital manufacturers of state-owned enterprises
随机推荐
What material is sa537cl2? Analysis of mechanical properties of American standard container plate
NSQ source code installation and operation process
Learn from me about the enterprise flutter project: simplified framework demo reference
关于学习Qt编程的好书精品推荐
Processing strategy of message queue message loss and repeated message sending
Informatics Olympiad all in one YBT 1175: divide by 13 | openjudge noi 1.13 27: divide by 13
Recommendation of good books on learning QT programming
14 topics for performance interviews between superiors and subordinates (4)
CC2530 common registers for port initialization
What material is sa537cl2 equivalent to in China? Sa537cl2 corresponding material
Overview of satellite navigation system
Custom plug-in construction and use of QT plug-in
爱可可AI前沿推介(7.3)
How to set up SVN server on this machine
[statement] about searching sogk1997 and finding many web crawler results
Necessary ability of data analysis
function overloading
Le zèbre a été identifié comme un chien, et la cause de l'erreur d'AI a été trouvée par Stanford
Characteristic polynomial and constant coefficient homogeneous linear recurrence
Zebras are recognized as dogs, and Stanford found the reason why AI made mistakes