--- old/src/solaris/classes/java/lang/UNIXProcess.java.solaris Thu Nov 22 21:04:33 2012 +++ new/src/solaris/classes/java/lang/UNIXProcess.java.solaris Thu Nov 22 21:04:31 2012 @@ -27,6 +27,8 @@ import java.io.*; import java.util.concurrent.TimeUnit; +import java.security.AccessController; +import java.security.PrivilegedAction; /* java.lang.Process subclass in the UNIX environment. * @@ -46,11 +48,52 @@ private DeferredCloseInputStream stdout_inner_stream; private InputStream stderr_stream; + private static String javahome; + private static String arch; + private static String helperpath; + + enum LaunchMechanism { + CLONE(1), FORK(2), + VFORK(3), SPAWN(4); + + private int value; + LaunchMechanism(int x) {value = x;} + }; + + /* On Solaris, the default is to spawn */ + private static LaunchMechanism launchMechanism = LaunchMechanism.SPAWN; + + static { + AccessController.doPrivileged(new PrivilegedAction() { + public Void run() { + String javahome = System.getProperty("java.home"); + + String osarch = System.getProperty("os.arch"); + if (osarch.equals("sparcv9") || osarch.equals("amd64")) { + osarch += "/"; + } else { + osarch = ""; + } + + helperpath = javahome + "/bin/" + osarch + "jprochelper"; + String s = System.getProperty("java.lang.useFork"); + if (s != null) { + launchMechanism = LaunchMechanism.FORK; + } + return null; + } + }); + } + /* 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) + * - vfork(2) and exec(2) + * - posix_spawn(2) * * @param std_fds array of file descriptors. Indexes 0, 1, and * 2 correspond to standard input, standard output and @@ -62,7 +105,7 @@ * if and only if it is not -1 on output. * @return the pid of the subprocess */ - private native int forkAndExec(byte[] prog, + private native int forkAndExec(int mode, byte[] prog, byte[] argBlock, int argc, byte[] envBlock, int envc, byte[] dir, @@ -77,7 +120,8 @@ final int[] std_fds, final boolean redirectErrorStream) throws IOException { - pid = forkAndExec(prog, + pid = forkAndExec(launchMechanism.value, + prog, argBlock, argc, envBlock, envc, dir,