8274293: Build failure on macOS with Xcode 13.0 as vfork is deprecated

Reviewed-by: alanb, stuefe, rriggs
This commit is contained in:
bobpengxie 2021-09-26 14:48:19 +00:00 committed by Jie Fu
parent 7700b25460
commit 252aaa9249
2 changed files with 10 additions and 2 deletions
src
hotspot/os/posix
java.base/unix/native/libjava

@ -1946,7 +1946,11 @@ int os::fork_and_exec(const char* cmd, bool prefer_vfork) {
// Use always vfork on AIX, since its safe and helps with analyzing OOM situations.
// Otherwise leave it up to the caller.
AIX_ONLY(prefer_vfork = true;)
#ifdef __APPLE__
pid = ::fork();
#else
pid = prefer_vfork ? ::vfork() : ::fork();
#endif
if (pid < 0) {
// fork failed

@ -444,7 +444,8 @@ static int copystrings(char *buf, int offset, const char * const *arg) {
__attribute_noinline__
#endif
/* vfork(2) is deprecated on Solaris */
/* vfork(2) is deprecated on Darwin */
#ifndef __APPLE__
static pid_t
vforkChild(ChildStuff *c) {
volatile pid_t resultPid;
@ -463,6 +464,7 @@ vforkChild(ChildStuff *c) {
assert(resultPid != 0); /* childProcess never returns */
return resultPid;
}
#endif
static pid_t
forkChild(ChildStuff *c) {
@ -573,9 +575,11 @@ spawnChild(JNIEnv *env, jobject process, ChildStuff *c, const char *helperpath)
static pid_t
startChild(JNIEnv *env, jobject process, ChildStuff *c, const char *helperpath) {
switch (c->mode) {
/* vfork(2) is deprecated on Solaris */
/* vfork(2) is deprecated on Darwin*/
#ifndef __APPLE__
case MODE_VFORK:
return vforkChild(c);
#endif
case MODE_FORK:
return forkChild(c);
case MODE_POSIX_SPAWN: