8212828: (process) Provide a way for Runtime.exec to use posix_spawn on linux
authorstuefe
Thu, 18 Oct 2018 15:56:37 -0500
changeset 52364 750b500ef4de
parent 52363 7e236f262add
child 52365 45e3d52aaced
8212828: (process) Provide a way for Runtime.exec to use posix_spawn on linux Reviewed-by: alanb, rriggs Contributed-by: david.lloyd@redhat.com
make/launcher/Launcher-java.base.gmk
src/java.base/unix/classes/java/lang/ProcessImpl.java
src/java.base/unix/native/libjava/ProcessImpl_md.c
test/jdk/java/lang/ProcessBuilder/Basic.java
--- a/make/launcher/Launcher-java.base.gmk	Wed Oct 31 19:56:51 2018 -0700
+++ b/make/launcher/Launcher-java.base.gmk	Thu Oct 18 15:56:37 2018 -0500
@@ -84,7 +84,7 @@
 
 ################################################################################
 
-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, \
--- a/src/java.base/unix/classes/java/lang/ProcessImpl.java	Wed Oct 31 19:56:51 2018 -0700
+++ b/src/java.base/unix/classes/java/lang/ProcessImpl.java	Thu Oct 18 15:56:37 2018 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -89,7 +89,7 @@
 
     private static enum Platform {
 
-        LINUX(LaunchMechanism.VFORK, LaunchMechanism.FORK),
+        LINUX(LaunchMechanism.VFORK, LaunchMechanism.POSIX_SPAWN, LaunchMechanism.FORK),
 
         BSD(LaunchMechanism.POSIX_SPAWN, LaunchMechanism.FORK),
 
--- a/src/java.base/unix/native/libjava/ProcessImpl_md.c	Wed Oct 31 19:56:51 2018 -0700
+++ b/src/java.base/unix/native/libjava/ProcessImpl_md.c	Thu Oct 18 15:56:37 2018 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -44,9 +44,7 @@
 #include <signal.h>
 #include <string.h>
 
-#if defined(__solaris__) || defined(_ALLBSD_SOURCE) || defined(_AIX)
 #include <spawn.h>
-#endif
 
 #include "childproc.h"
 
@@ -390,7 +388,6 @@
     return resultPid;
 }
 
-#if defined(__solaris__) || defined(_ALLBSD_SOURCE) || defined(_AIX)
 static pid_t
 spawnChild(JNIEnv *env, jobject process, ChildStuff *c, const char *helperpath) {
     pid_t resultPid;
@@ -473,7 +470,6 @@
      * via the statement below */
     return resultPid;
 }
-#endif
 
 /*
  * Start a child process running function childProcess.
@@ -489,10 +485,8 @@
 #endif
       case MODE_FORK:
         return forkChild(c);
-#if defined(__solaris__) || defined(_ALLBSD_SOURCE) || defined(_AIX)
       case MODE_POSIX_SPAWN:
         return spawnChild(env, process, c, helperpath);
-#endif
       default:
         return -1;
     }
--- a/test/jdk/java/lang/ProcessBuilder/Basic.java	Wed Oct 31 19:56:51 2018 -0700
+++ b/test/jdk/java/lang/ProcessBuilder/Basic.java	Thu Oct 18 15:56:37 2018 -0500
@@ -36,6 +36,13 @@
  * @author Martin Buchholz
  */
 
+/*
+ * @test
+ * @modules java.base/java.lang:open
+ * @requires (os.family == "linux")
+ * @run main/othervm/timeout=300 -Djdk.lang.Process.launchMechanism=posix_spawn Basic
+ */
+
 import java.lang.ProcessBuilder.Redirect;
 import java.lang.ProcessHandle;
 import static java.lang.ProcessBuilder.Redirect.*;