当前位置:网站首页>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
边栏推荐
- 斑马识别成狗,AI犯错的原因被斯坦福找到了
- The word backspace key cannot delete the selected text, so you can only press Delete
- Cocos Creator 2. X automatic packaging (build + compile)
- 特征多项式与常系数齐次线性递推
- Register in PHP_ Globals parameter settings
- (补)双指针专题
- Interpretation of several important concepts of satellite antenna
- 执行脚本不认\r
- Pointcut expression
- 利用MySQL中的乐观锁和悲观锁实现分布式锁
猜你喜欢

Mysql database -dql

Google Earth engine (GEE) - daymet v4: daily surface weather data set (1000m resolution) including data acquisition methods for each day

Yu Wenwen, Hu Xia and other stars take you to play with the party. Pipi app ignites your summer

CC2530 common registers for timer 1

Web crawler knowledge day03

A survey of state of the art on visual slam
![[combinatorics] polynomial theorem (polynomial theorem | polynomial theorem proof | polynomial theorem inference 1 item number is the number of non negative integer solutions | polynomial theorem infe](/img/9d/6118b699c0d90810638f9b08d4f80a.jpg)
[combinatorics] polynomial theorem (polynomial theorem | polynomial theorem proof | polynomial theorem inference 1 item number is the number of non negative integer solutions | polynomial theorem infe

为抵制 7-Zip,列出 “三宗罪” ?网友:“第3个才是重点吧?”

NSQ source code installation and operation process

utfwry. Dat PHP, about ThinkPHP's method of IP location using utfwry address Library
随机推荐
[Jianzhi offer] 64 Find 1+2+... +n
NSQ源码安装运行过程
NLP四范式:范式一:非神经网络时代的完全监督学习(特征工程);范式二:基于神经网络的完全监督学习(架构工程);范式三:预训练,精调范式(目标工程);范式四:预训练,提示,预测范式(Prompt工程)
8个酷炫可视化图表,快速写出老板爱看的可视化分析报告
Basis of target detection (IOU)
Golang decorator mode and its use in NSQ
【LeetCode】94. Middle order traversal of binary tree
香港理工大学|数据高效的强化学习和网络流量动态的自适应最优周界控制
Zebras are recognized as dogs, and Stanford found the reason why AI made mistakes
利用MySQL中的乐观锁和悲观锁实现分布式锁
消息队列消息丢失和消息重复发送的处理策略
网络安全web渗透技术
Preventing/catching “IllegalArgumentException: parameter must be a descendant of this view” error
Difference between JSON and bson
Thread pool executes scheduled tasks
Daily code 300 lines learning notes day 10
MySQL Basics
Thinking about telecommuting under the background of normalization of epidemic | community essay solicitation
斑马识别成狗,AI犯错的原因被斯坦福找到了
"The NTP socket is in use, exiting" appears when ntpdate synchronizes the time