--- old/src/solaris/classes/java/lang/UNIXProcess.java.bsd Wed Nov 13 16:42:36 2013 +++ new/src/solaris/classes/java/lang/UNIXProcess.java.bsd Wed Nov 13 16:42:36 2013 @@ -63,11 +63,59 @@ private /* final */ InputStream stdout; private /* final */ InputStream stderr; + private static enum LaunchMechanism { + FORK(1), + POSIX_SPAWN(2); + + private int value; + LaunchMechanism(int x) {value = x;} + }; + + /* On BSD, the default is to spawn */ + private static final LaunchMechanism launchMechanism; + private static byte[] helperpath; + + private static byte[] toCString(String s) { + if (s == null) + return null; + byte[] bytes = s.getBytes(); + byte[] result = new byte[bytes.length + 1]; + System.arraycopy(bytes, 0, + result, 0, + bytes.length); + result[result.length-1] = (byte)0; + return result; + } + + static { + launchMechanism = AccessController.doPrivileged( + new PrivilegedAction() + { + public LaunchMechanism run() { + String javahome = System.getProperty("java.home"); + + helperpath = toCString(javahome + "/lib/jspawnhelper"); + String s = System.getProperty( + "jdk.lang.Process.launchMechanism", "posix_spawn"); + + try { + return LaunchMechanism.valueOf(s.toUpperCase()); + } catch (IllegalArgumentException e) { + throw new Error(s + " is not a supported " + + "process launch mechanism on this platform."); + } + } + }); + } + /* this is for the reaping thread */ private native int waitForProcessExit(int pid); /** - * Create a process using fork(2) and exec(2). + * Create a process. Depending on the mode flag, this is done by + * one of the following mechanisms. + * - fork(2) and exec(2) + * - posix_spawn(2) * * @param fds an array of three file descriptors. * Indexes 0, 1, and 2 correspond to standard input, @@ -80,7 +128,8 @@ * output. * @return the pid of the subprocess */ - private native int forkAndExec(byte[] prog, + private native int forkAndExec(int mode, byte[] helperpath, + byte[] prog, byte[] argBlock, int argc, byte[] envBlock, int envc, byte[] dir, @@ -132,7 +181,9 @@ final boolean redirectErrorStream) throws IOException { - pid = forkAndExec(prog, + pid = forkAndExec(launchMechanism.value, + helperpath, + prog, argBlock, argc, envBlock, envc, dir, @@ -236,11 +287,10 @@ try { stderr.close(); } catch (IOException ignored) {} } - /* This routine initializes JNI field offsets for the class */ - private static native void initIDs(); + private static native void init(); static { - initIDs(); + init(); } /**