6850720: Allow POSIX_SPAWN to be used for ProcessImpl on Linux

Thomas Stüfe thomas.stuefe at gmail.com
Tue Oct 23 14:01:41 UTC 2018


Oh, I can open a bug report on JBS for you. Should I?

(Now I understand the "reuse bug id").


On Tue, Oct 23, 2018 at 3:18 PM David Lloyd <david.lloyd at redhat.com> wrote:
>
> I've submitted a bug report via bugreport.java.com.  If/when it gets
> promoted to a proper JIRA with an issue number, I'll see if I can put
> the patch up on jdk/submit.
> On Thu, Oct 18, 2018 at 4:42 PM David Lloyd <david.lloyd at redhat.com> wrote:
> >
> > The issue 6850720 isn't _exactly_ to use POSIX_SPAWN for process
> > launching on Linux, but it's the closest I could find out of what are
> > really a surprisingly large number of issues that refer to posix_spawn
> > in one way or another relating to ProcessImpl.  There's a different
> > issue to move from vfork to posix_spawn on Solaris, but I wasn't sure
> > if that one was quite right to hang this off of.  Maybe it should be
> > yet another issue of its own.
> >
> > Anyway: this is a follow-up to the email thread entitled "Runtime.exec
> > : vfork() concerns and a fix proposal", where it was casually
> > mentioned that maybe posix_spawn could become an option on Linux,
> > whereafter it could be thoroughly tested by brave individuals and
> > eventually maybe become the default on that platform, obsoleting the
> > vfork support for good.
> >
> > The following patch does just that.  I've tested it launching a
> > multi-process WildFly instance a bunch of times, in conjunction with
> > the conveniently existent "jdk.lang.Process.launchMechanism" property,
> > and nothing exploded so here it is.  The usual deal with git patches:
> > apply directly through "patch -p1".
> >
> > commit f0eb9ff7c46dff76f91160491fcca0eb25d0ab95
> > Author: David M. Lloyd <david.lloyd at redhat.com>
> > Date:   Thu Oct 18 15:56:37 2018 -0500
> >
> >     [JDK-6850720] Enable POSIX_SPAWN as an option for child process
> > creation on Linux
> >
> > diff --git a/make/launcher/Launcher-java.base.gmk
> > b/make/launcher/Launcher-java.base.gmk
> > index 0ce0287d2be..c28fe42d102 100644
> > --- a/make/launcher/Launcher-java.base.gmk
> > +++ b/make/launcher/Launcher-java.base.gmk
> > @@ -84,7 +84,7 @@ endif
> >
> >  ################################################################################
> >
> > -ifneq ($(findstring $(OPENJDK_TARGET_OS), macosx solaris aix), )
> > +ifneq ($(findstring $(OPENJDK_TARGET_OS), macosx solaris aix linux), )
> >    $(eval $(call SetupJdkExecutable, BUILD_JSPAWNHELPER, \
> >        NAME := jspawnhelper, \
> >        SRC := $(TOPDIR)/src/$(MODULE)/unix/native/jspawnhelper, \
> > diff --git a/src/java.base/unix/classes/java/lang/ProcessImpl.java
> > b/src/java.base/unix/classes/java/lang/ProcessImpl.java
> > index 368a4f7380b..959e50dfecd 100644
> > --- a/src/java.base/unix/classes/java/lang/ProcessImpl.java
> > +++ b/src/java.base/unix/classes/java/lang/ProcessImpl.java
> > @@ -89,7 +89,7 @@ final class ProcessImpl extends Process {
> >
> >      private static enum Platform {
> >
> > -        LINUX(LaunchMechanism.VFORK, LaunchMechanism.FORK),
> > +        LINUX(LaunchMechanism.VFORK, LaunchMechanism.POSIX_SPAWN,
> > LaunchMechanism.FORK),
> >
> >          BSD(LaunchMechanism.POSIX_SPAWN, LaunchMechanism.FORK),
> >
> > diff --git a/src/java.base/unix/native/libjava/ProcessImpl_md.c
> > b/src/java.base/unix/native/libjava/ProcessImpl_md.c
> > index 533584fdb7a..6869a64f2cc 100644
> > --- a/src/java.base/unix/native/libjava/ProcessImpl_md.c
> > +++ b/src/java.base/unix/native/libjava/ProcessImpl_md.c
> > @@ -44,7 +44,7 @@
> >  #include <signal.h>
> >  #include <string.h>
> >
> > -#if defined(__solaris__) || defined(_ALLBSD_SOURCE) || defined(_AIX)
> > +#if defined(__solaris__) || defined(_ALLBSD_SOURCE) || defined(_AIX)
> > || defined(__linux__)
> >  #include <spawn.h>
> >  #endif
> >
> > @@ -390,7 +390,7 @@ forkChild(ChildStuff *c) {
> >      return resultPid;
> >  }
> >
> > -#if defined(__solaris__) || defined(_ALLBSD_SOURCE) || defined(_AIX)
> > +#if defined(__solaris__) || defined(_ALLBSD_SOURCE) || defined(_AIX)
> > || defined(__linux__)
> >  static pid_t
> >  spawnChild(JNIEnv *env, jobject process, ChildStuff *c, const char
> > *helperpath) {
> >      pid_t resultPid;
> > @@ -489,7 +489,7 @@ startChild(JNIEnv *env, jobject process,
> > ChildStuff *c, const char *helperpath)
> >  #endif
> >        case MODE_FORK:
> >          return forkChild(c);
> > -#if defined(__solaris__) || defined(_ALLBSD_SOURCE) || defined(_AIX)
> > +#if defined(__solaris__) || defined(_ALLBSD_SOURCE) || defined(_AIX)
> > || defined(__linux__)
> >        case MODE_POSIX_SPAWN:
> >          return spawnChild(env, process, c, helperpath);
> >  #endif
>
>
>
> --
> - DML


More information about the core-libs-dev mailing list