当从 JNI 线程调用 fork()
时,Java 堆会发生什么情况。 Java 堆是否重复?
native 内存部分、JNI 内存、类内存、线程内存和线程本地堆 (TLH) 会发生什么情况?
最佳答案
调用fork()
后,JVM作为子进程将无法工作。每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 theexec
functions is called.
JVM 是一个多线程进程,JNI 调用和 Java 函数不是 POSIX 异步信号安全函数调用。
参见2.4 Signal Concepts对于函数调用列表,POSIX 要求是异步信号安全的。
那么,Java 堆和其他 JVM 特定的内存会发生什么情况?它们通常通过copy-on-write复制到子进程的虚拟地址空间中。 ,但如果您尝试在子进程中继续执行 JVM,它们实际上将无法使用。它们处于未知状态,例如,锁可能由不存在的线程持有。
关于java - 当从 JNI 线程调用 fork 时,Java 堆会发生什么情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51888447/