当前位置:网站首页>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
边栏推荐
- Cocos Creator 2.x 自动打包(构建 + 编译)
- 【剑指 Offer 】64. 求1+2+…+n
- Visual SLAM algorithms: a survey from 2010 to 2016
- 利用MySQL中的乐观锁和悲观锁实现分布式锁
- [combinatorial mathematics] counting model, common combinatorial numbers and combinatorial identities**
- NLP four paradigms: paradigm 1: fully supervised learning in the era of non neural networks (Feature Engineering); Paradigm 2: fully supervised learning based on neural network (Architecture Engineeri
- What material is 12cr1movr? Chemical property analysis of pressure vessel steel plate 12cr1movr
- Interpretation of several important concepts of satellite antenna
- Golang decorator mode and its use in NSQ
- Mysql database -dql
猜你喜欢

Visual SLAM algorithms: a survey from 2010 to 2016

arduino-esp32:LVGL项目(一)整体框架

2022 love analysis · panoramic report of digital manufacturers of state-owned enterprises

Processing strategy of message queue message loss and repeated message sending

跟我学企业级flutter项目:简化框架demo参考

There are several APIs of airtest and poco that are easy to use wrong in "super". See if you have encountered them

Pytorch 1.12 was released, officially supporting Apple M1 chip GPU acceleration and repairing many bugs

NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon

CC2530 common registers for serial communication

NLP四范式:范式一:非神经网络时代的完全监督学习(特征工程);范式二:基于神经网络的完全监督学习(架构工程);范式三:预训练,精调范式(目标工程);范式四:预训练,提示,预测范式(Prompt工程)
随机推荐
利用MySQL中的乐观锁和悲观锁实现分布式锁
PHP secondary domain name session sharing scheme
What material is 13crmo4-5 equivalent to in China? 13crmo4-5 chemical composition 13crmo4-5 mechanical properties
CC2530 common registers for crystal oscillator settings
utfwry. Dat PHP, about ThinkPHP's method of IP location using utfwry address Library
CC2530 common registers for ADC single channel conversion
【剑指 Offer 】64. 求1+2+…+n
NLP四范式:范式一:非神经网络时代的完全监督学习(特征工程);范式二:基于神经网络的完全监督学习(架构工程);范式三:预训练,精调范式(目标工程);范式四:预训练,提示,预测范式(Prompt工程)
What is the difference between 14Cr1MoR container plate and 14Cr1MoR (H)? Chemical composition and performance analysis of 14Cr1MoR
Construction practice camp - graduation summary of phase 6
Add color to the interface automation test framework and realize the enterprise wechat test report
CC2530 common registers
Processing strategy of message queue message loss and repeated message sending
What material is 12cr1movr? Chemical property analysis of pressure vessel steel plate 12cr1movr
function overloading
CC2530 common registers for timer 1
[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
MySQL single table field duplicate data takes the latest SQL statement
How programming apes grow rapidly
Record windows10 installation tensorflow-gpu2.4.0