简体   繁体   中英

What happens to Java heap when fork is called from JNI thread

What happens to Java heap when fork() is called from JNI thread. Is the Java heap duplicated?

What will happen to native memory sections, JNI memory, Class Memory, Thread memory, and Thread Local Heap (TLH)?

After calling fork() , the JVM as the child process will not work. Per the POSIX documentation on fork() :

A process shall be created with a single thread. If a multi-threaded process calls fork() , the new process shall contain a replica of the calling thread and its entire address space, possibly including the states of mutexes and other resources. Consequently, to avoid errors, the child process may only execute async-signal-safe operations until such time as one of the exec functions is called.

A JVM is a multithreaded process, and JNI calls and Java functions are not POSIX async-signal-safe function calls.

See 2.4 Signal Concepts for the list of function calls POSIX requires to be async-signal-safe.

So, what happens to the Java heap, and other JVM-specific memory? They're copied into the child process's virtual address space, normally via copy-on-write , but they're effectively unusable should you try continuing JVM execution in the child process. They're in an unknown state, with locks potentially held by non-existent threads, for example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM