java - 当从 JNI 线程调用 fork 时,Java 堆会发生什么情况

标签 java java-native-interface

当从 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 the exec 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/

相关文章:

javascript - NodeJS 与 Java RESTful 后端?

java - 将 Action 监听器添加到字符串

c++ - Android Studio 中外部剥离共享库的原生调试

java - float 从 jni 返回到 java 收到错误结果

java - 如何使用Stream过滤嵌套对象?

Java swing mousemove 只触发一次

java - 使用 API(Java?)在 Facebook 粉丝页面上发布状态

java - 使用 cygwin 为 JNI (Android NDK) 编译 C++ 代码

Android NDK 和 Gradle : Different Android. mk 每个构建类型

c++ - 从 std::wstring 转换为 jstring