RFR: JDK-8274320: os::fork_and_exec() should be using posix_spawn

Thomas Stuefe stuefe at openjdk.java.net
Fri Oct 15 04:36:49 UTC 2021


On Sat, 25 Sep 2021 16:16:29 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:

> Hi, may I have reviews for this small patch please?
> 
> `os::fork_and_exec()`, used in the hotspot to spawn child programs (scripts etc) in error situations, should be using `posix_spawn()`. 
> 
> ATM it uses either `fork()` or `vfork()`. `vfork()` got deprecated on MacOS and we get build errors (JDK-8274293) - even though in this case it would be completely fine to use. This leaves us with `fork()` for MacOS, which has the known problems with large-footprint-parents. This matters here especially since we also use os::fork_and_exec to implement `-XX:OnError` for OOM situations.
> 
> We already use posix_spawn() as default for Runtime.exec() since JDK 15, and it is available on all our Unices. We also should use it here.
> 
> I kept the name of the function (fork_and_exec) since people know it, even though it's more incorrect now than before.
> 
> Tests:
> - manual tests using -XX:OnError with various scripts, including checking that env variables are passed correctly
> - manually ran runtime/ErrorHandling tests
> - GHAs

Hi Xin, thanks for giving this an eye.

> When it comes to Linux/glibc, Linux kernel has Copy-On-Write feature, doesn't it? So this change can't improve Linux further.
> 

Not completely true, since AFAIU you need to at least copy the page tables. posix_spawn (if it uses clone(VFORK) under the hood) should not need to copy the page tables.

> On the other side, Darwin can take benefit from it by changing from fork() to posix_spawn(). If so, why not just use ifdef **APPLE** posix_spwarn() on Darwin? VMError has already used the macro for the vfork issue.

My aim was to simplify the code, not make it more complex. If the argument is "posix_spawn is dangerous during error reporting" we should not use it at all. If that argument does not hold, we can use it on all platforms.

Thanks, Thomas

-------------

PR: https://git.openjdk.java.net/jdk/pull/5698


More information about the hotspot-runtime-dev mailing list