diff options
author | Tom Tromey <tromey@redhat.com> | 2007-03-05 15:57:13 +0000 |
---|---|---|
committer | Tom Tromey <tromey@gcc.gnu.org> | 2007-03-05 15:57:13 +0000 |
commit | f4a2a1deec8e1c2c8f9ed80d166a37341fbafd19 (patch) | |
tree | ade62852d2118479bf46fcdfc3db7466a4d05e58 /libjava/java | |
parent | 344189f9ec005682d1e5d6a700b91184e58538b8 (diff) | |
download | gcc-f4a2a1deec8e1c2c8f9ed80d166a37341fbafd19.zip gcc-f4a2a1deec8e1c2c8f9ed80d166a37341fbafd19.tar.gz gcc-f4a2a1deec8e1c2c8f9ed80d166a37341fbafd19.tar.bz2 |
sources.am, [...]: Rebuilt.
* sources.am, Makefile.in: Rebuilt.
* scripts/makemake.tcl (emit_package_rule): Don't omit
VMProcess.java.
* Makefile.am (nat_source_files): Added natVMProcess.cc.
(inner_nat_headers): Added ImmediateEOFInputStream.h.
* gcj/javaprims.h: Regenerated.
* java/lang/System.java (EnvironmentMap): Now package-private.
(EnvironmentMap(Map)): New constructor.
(EnvironmentMap.put): New method.
* java/lang/natWin32Process.cc (startProcess): Update.
* java/lang/Win32Process.java (Win32Process): Added 'redirect'
argument.
(startProcess): Likewise.
* java/lang/EcosProcess.java (EcosProcess): Added 'redirect'
argument.
* java/lang/natPosixProcess.cc (nativeSpawn): Handle redirection.
* java/lang/PosixProcess.java (redirect): New field.
(PosixProcess): Added 'redirect' argument.
* java/lang/natRuntime.cc (execInternal): Added 'redirect'
argument to Process creation.
* java/lang/natVMProcess.cc: New file.
* java/lang/ProcessBuilder.java: Removed.
* java/lang/VMProcess.java: New file.
From-SVN: r122553
Diffstat (limited to 'libjava/java')
-rw-r--r-- | libjava/java/lang/EcosProcess.h | 2 | ||||
-rw-r--r-- | libjava/java/lang/EcosProcess.java | 7 | ||||
-rw-r--r-- | libjava/java/lang/PosixProcess.h | 3 | ||||
-rw-r--r-- | libjava/java/lang/PosixProcess.java | 8 | ||||
-rw-r--r-- | libjava/java/lang/System$EnvironmentMap.h | 3 | ||||
-rw-r--r-- | libjava/java/lang/System.java | 44 | ||||
-rw-r--r-- | libjava/java/lang/VMProcess.h | 24 | ||||
-rw-r--r-- | libjava/java/lang/VMProcess.java (renamed from libjava/java/lang/ProcessBuilder.java) | 92 | ||||
-rw-r--r-- | libjava/java/lang/Win32Process.h | 4 | ||||
-rw-r--r-- | libjava/java/lang/Win32Process.java | 14 | ||||
-rw-r--r-- | libjava/java/lang/natPosixProcess.cc | 58 | ||||
-rw-r--r-- | libjava/java/lang/natRuntime.cc | 4 | ||||
-rw-r--r-- | libjava/java/lang/natVMProcess.cc | 34 | ||||
-rw-r--r-- | libjava/java/lang/natWin32Process.cc | 7 |
14 files changed, 185 insertions, 119 deletions
diff --git a/libjava/java/lang/EcosProcess.h b/libjava/java/lang/EcosProcess.h index 30fd067..a0173c3 100644 --- a/libjava/java/lang/EcosProcess.h +++ b/libjava/java/lang/EcosProcess.h @@ -20,7 +20,7 @@ public: ::java::io::InputStream * getInputStream(); ::java::io::OutputStream * getOutputStream(); jint waitFor(); - EcosProcess(JArray< ::java::lang::String * > *, JArray< ::java::lang::String * > *, ::java::io::File *); + EcosProcess(JArray< ::java::lang::String * > *, JArray< ::java::lang::String * > *, ::java::io::File *, jboolean); static ::java::lang::Class class$; }; diff --git a/libjava/java/lang/EcosProcess.java b/libjava/java/lang/EcosProcess.java index 30c8253..79c2f12 100644 --- a/libjava/java/lang/EcosProcess.java +++ b/libjava/java/lang/EcosProcess.java @@ -1,6 +1,6 @@ // EcosProcess.java - Subclass of Process for eCos systems. -/* Copyright (C) 1998, 1999, 2006 Free Software Foundation +/* Copyright (C) 1998, 1999, 2006, 2007 Free Software Foundation This file is part of libgcj. @@ -51,9 +51,8 @@ final class EcosProcess extends Process return 0; } - public EcosProcess (String[] progarray, - String[] envp, - File dir) + public EcosProcess (String[] progarray, String[] envp, File dir, + boolean redirect) throws IOException { throw new IOException ("eCos processes unimplemented"); diff --git a/libjava/java/lang/PosixProcess.h b/libjava/java/lang/PosixProcess.h index 62539ce..a43fa07 100644 --- a/libjava/java/lang/PosixProcess.h +++ b/libjava/java/lang/PosixProcess.h @@ -31,7 +31,7 @@ public: // actually package-private private: void nativeSpawn(); public: // actually package-private - PosixProcess(JArray< ::java::lang::String * > *, JArray< ::java::lang::String * > *, ::java::io::File *); + PosixProcess(JArray< ::java::lang::String * > *, JArray< ::java::lang::String * > *, ::java::io::File *, jboolean); static jlong access$0(::java::lang::PosixProcess *); static ::java::lang::Object * access$1(); static void access$2(::java::lang::PosixProcess$ProcessManager *); @@ -39,6 +39,7 @@ private: JArray< ::java::lang::String * > * __attribute__((aligned(__alignof__( ::java::lang::Process)))) progarray; JArray< ::java::lang::String * > * envp; ::java::io::File * dir; + jboolean redirect; ::java::lang::Throwable * exception; jlong pid; public: // actually package-private diff --git a/libjava/java/lang/PosixProcess.java b/libjava/java/lang/PosixProcess.java index 517e6f3..6b14964 100644 --- a/libjava/java/lang/PosixProcess.java +++ b/libjava/java/lang/PosixProcess.java @@ -1,5 +1,5 @@ // PosixProcess.java - Subclass of Process for POSIX systems. -/* Copyright (C) 1998, 1999, 2004, 2006 Free Software Foundation +/* Copyright (C) 1998, 1999, 2004, 2006, 2007 Free Software Foundation This file is part of libgcj. @@ -354,8 +354,8 @@ final class PosixProcess extends Process */ private native void nativeSpawn(); - PosixProcess(String[] progarray, String[] envp, File dir) - throws IOException + PosixProcess(String[] progarray, String[] envp, File dir, boolean redirect) + throws IOException { // Check to ensure there is something to run, and avoid // dereferencing null pointers in native code. @@ -365,6 +365,7 @@ final class PosixProcess extends Process this.progarray = progarray; this.envp = envp; this.dir = dir; + this.redirect = redirect; // Start a ProcessManager if there is not one already running. synchronized (queueLock) @@ -419,6 +420,7 @@ final class PosixProcess extends Process private String[] progarray; private String[] envp; private File dir; + private boolean redirect; /** Set by the ProcessManager on problems starting. */ private Throwable exception; diff --git a/libjava/java/lang/System$EnvironmentMap.h b/libjava/java/lang/System$EnvironmentMap.h index ee4582b..1220f57 100644 --- a/libjava/java/lang/System$EnvironmentMap.h +++ b/libjava/java/lang/System$EnvironmentMap.h @@ -13,16 +13,19 @@ class java::lang::System$EnvironmentMap : public ::java::util::HashMap public: // actually package-private System$EnvironmentMap(); + System$EnvironmentMap(::java::util::Map *); public: virtual jboolean containsKey(::java::lang::Object *); virtual jboolean containsValue(::java::lang::Object *); virtual ::java::util::Set * entrySet(); virtual ::java::lang::String * target$get(::java::lang::Object *); virtual ::java::util::Set * keySet(); + virtual ::java::lang::String * target$put(::java::lang::String *, ::java::lang::String *); virtual ::java::lang::String * target$remove(::java::lang::Object *); virtual ::java::util::Collection * values(); virtual ::java::lang::Object * get(::java::lang::Object *); virtual ::java::lang::Object * remove(::java::lang::Object *); + virtual ::java::lang::Object * put(::java::lang::Object *, ::java::lang::Object *); private: ::java::util::Set * __attribute__((aligned(__alignof__( ::java::util::HashMap)))) entries; ::java::util::Set * keys; diff --git a/libjava/java/lang/System.java b/libjava/java/lang/System.java index 76a39f0..b516a51 100644 --- a/libjava/java/lang/System.java +++ b/libjava/java/lang/System.java @@ -828,7 +828,7 @@ public final class System * * @author Andrew John Hughes (gnu_andrew@member.fsf.org) */ - private static class EnvironmentMap + static class EnvironmentMap extends HashMap<String,String> { @@ -854,7 +854,20 @@ public final class System { super(); } - + + /** + * Constructs a new <code>EnvironmentMap</code> containing + * the contents of the specified map. + * + * @param m the map to be added to this. + * @throws NullPointerException if a key or value is null. + * @throws ClassCastException if a key or value is not a String. + */ + EnvironmentMap(Map<String,String> m) + { + super(m); + } + /** * Blocks queries containing a null key or one which is not * of type <code>String</code>. All other queries @@ -939,7 +952,32 @@ public final class System keys = new EnvironmentSet(super.keySet()); return keys; } - + + /** + * Associates the given key to the given value. If the + * map already contains the key, its value is replaced. + * The map does not accept null keys or values, or keys + * and values not of type {@link String}. + * + * @param key the key to map. + * @param value the value to be mapped. + * @return the previous value of the key, or null if there was no mapping + * @throws NullPointerException if a key or value is null. + * @throws ClassCastException if a key or value is not a String. + */ + public String put(String key, String value) + { + if (key == null) + throw new NullPointerException("A new key is null."); + if (value == null) + throw new NullPointerException("A new value is null."); + if (!(key instanceof String)) + throw new ClassCastException("A new key is not a String."); + if (!(value instanceof String)) + throw new ClassCastException("A new value is not a String."); + return super.put(key, value); + } + /** * Removes a key-value pair from the map. The queried key may not * be null or of a type other than a <code>String</code>. diff --git a/libjava/java/lang/VMProcess.h b/libjava/java/lang/VMProcess.h new file mode 100644 index 0000000..c0912e5 --- /dev/null +++ b/libjava/java/lang/VMProcess.h @@ -0,0 +1,24 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_lang_VMProcess__ +#define __java_lang_VMProcess__ + +#pragma interface + +#include <java/lang/Object.h> +#include <gcj/array.h> + + +class java::lang::VMProcess : public ::java::lang::Object +{ + +public: // actually package-private + VMProcess(); + static ::java::lang::Process * nativeExec(JArray< ::java::lang::String * > *, JArray< ::java::lang::String * > *, ::java::io::File *, jboolean); + static ::java::lang::Process * exec(::java::util::List *, ::java::util::Map *, ::java::io::File *, jboolean); +public: + static ::java::lang::Class class$; +}; + +#endif // __java_lang_VMProcess__ diff --git a/libjava/java/lang/ProcessBuilder.java b/libjava/java/lang/VMProcess.java index 440e5e0..c0c7beb 100644 --- a/libjava/java/lang/ProcessBuilder.java +++ b/libjava/java/lang/VMProcess.java @@ -1,5 +1,5 @@ -/* ProcessBuilder.java - Represent spawned system process - Copyright (C) 2005, 2006 Free Software Foundation, Inc. +/* java.lang.VMProcess -- VM implementation of java.lang.ProcessBuilder + Copyright (C) 2007 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -35,84 +35,34 @@ this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ - package java.lang; import java.io.File; import java.io.IOException; -import java.util.Arrays; +import java.util.Iterator; import java.util.List; import java.util.Map; -public final class ProcessBuilder +final class VMProcess { - private File directory = new File(System.getProperty("user.dir")); - private List<String> command; - // FIXME: make a copy. - private Map<String, String> environment = System.getenv(); - private boolean redirect = false; - - public ProcessBuilder(List<String> command) - { - this.command = command; - } - - public ProcessBuilder(String... command) - { - this.command = Arrays.asList(command); - } - - public List<String> command() - { - return command; - } - - public ProcessBuilder command(List<String> command) - { - this.command = command; - return this; - } - - public ProcessBuilder command(String... command) - { - this.command = Arrays.asList(command); - return this; - } - - public File directory() - { - return directory; - } - - public ProcessBuilder directory(File directory) - { - this.directory = directory; - return this; - } - - public Map<String, String> environment() - { - return environment; - } - - public boolean redirectErrorStream() - { - return redirect; - } - - public ProcessBuilder redirectErrorStream(boolean redirect) - { - this.redirect = redirect; - return this; - } + static native Process nativeExec(String[] cmd, String[] env, + File dir, boolean redirect) + throws IOException; - public Process start() throws IOException + static Process exec(List<String> cmd, Map<String, String> env, + File dir, boolean redirect) throws IOException { - SecurityManager sm = SecurityManager.current; // Be thread-safe! - if (sm != null) - sm.checkExec(command.get(0)); - // return VMProcess.exec(command, environment, directory, redirect); - // FIXME - return null; + String[] acmd = (String[]) cmd.toArray(new String[cmd.size()]); + String[] aenv = new String[env.size()]; + + int i = 0; + Iterator iter = env.entrySet().iterator(); + while (iter.hasNext()) + { + Map.Entry entry = (Map.Entry) iter.next(); + aenv[i++] = entry.getKey() + "=" + entry.getValue(); + } + + return nativeExec(acmd, aenv, dir, redirect); } } diff --git a/libjava/java/lang/Win32Process.h b/libjava/java/lang/Win32Process.h index 0b49c6e..5e22934 100644 --- a/libjava/java/lang/Win32Process.h +++ b/libjava/java/lang/Win32Process.h @@ -20,10 +20,10 @@ public: ::java::io::InputStream * getInputStream(); ::java::io::OutputStream * getOutputStream(); jint waitFor(); - Win32Process(JArray< ::java::lang::String * > *, JArray< ::java::lang::String * > *, ::java::io::File *); + Win32Process(JArray< ::java::lang::String * > *, JArray< ::java::lang::String * > *, ::java::io::File *, jboolean); private: jboolean hasExited(); - void startProcess(JArray< ::java::lang::String * > *, JArray< ::java::lang::String * > *, ::java::io::File *); + void startProcess(JArray< ::java::lang::String * > *, JArray< ::java::lang::String * > *, ::java::io::File *, jboolean); void cleanup(); ::java::io::OutputStream * __attribute__((aligned(__alignof__( ::java::lang::Process)))) outputStream; ::java::io::InputStream * inputStream; diff --git a/libjava/java/lang/Win32Process.java b/libjava/java/lang/Win32Process.java index 7d9e40f..e817a0c 100644 --- a/libjava/java/lang/Win32Process.java +++ b/libjava/java/lang/Win32Process.java @@ -1,6 +1,6 @@ // Win32Process.java - Subclass of Process for Win32 systems. -/* Copyright (C) 2002, 2003, 2006 Free Software Foundation +/* Copyright (C) 2002, 2003, 2006, 2007 Free Software Foundation This file is part of libgcj. @@ -51,9 +51,8 @@ final class Win32Process extends Process public native int waitFor () throws InterruptedException; - public Win32Process (String[] progarray, - String[] envp, - File dir) + public Win32Process (String[] progarray, String[] envp, File dir, + boolean redirect) throws IOException { for (int i = 0; i < progarray.length; i++) @@ -64,7 +63,7 @@ final class Win32Process extends Process progarray[i] = "\"" + s + "\""; } - startProcess (progarray, envp, dir); + startProcess (progarray, envp, dir, redirect); } // The standard streams (stdin, stdout and stderr, respectively) @@ -81,8 +80,9 @@ final class Win32Process extends Process private native boolean hasExited (); private native void startProcess (String[] progarray, - String[] envp, - File dir) + String[] envp, + File dir, + boolean redirect) throws IOException; private native void cleanup (); } diff --git a/libjava/java/lang/natPosixProcess.cc b/libjava/java/lang/natPosixProcess.cc index 4986470..149b5d8 100644 --- a/libjava/java/lang/natPosixProcess.cc +++ b/libjava/java/lang/natPosixProcess.cc @@ -1,6 +1,6 @@ // natPosixProcess.cc - Native side of POSIX process code. -/* Copyright (C) 1998, 1999, 2000, 2002, 2003, 2004, 2005, 2006 Free Software Foundation +/* Copyright (C) 1998, 1999, 2000, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation This file is part of libgcj. @@ -41,6 +41,7 @@ details. */ #include <java/io/FileOutputStream.h> #include <java/io/IOException.h> #include <java/lang/OutOfMemoryError.h> +#include <java/lang/PosixProcess$EOFInputStream.h> using gnu::java::nio::channels::FileChannelImpl; @@ -231,7 +232,7 @@ java::lang::PosixProcess::nativeSpawn () try { // Transform arrays to native form. - args = (char **) _Jv_Malloc ((progarray->length + 1) * sizeof (char *)); + args = (char **) _Jv_Malloc ((progarray->length + 1) * sizeof (char *)); // Initialize so we can gracefully recover. jstring *elts = elements (progarray); @@ -262,23 +263,30 @@ java::lang::PosixProcess::nativeSpawn () path = new_string (dir->getPath ()); // Create pipes for I/O. MSGP is for communicating exec() - // status. - if (pipe (inp) || pipe (outp) || pipe (errp) || pipe (msgp) + // status. If redirecting stderr to stdout, we don't need to + // create the ERRP pipe. + if (pipe (inp) || pipe (outp) || pipe (msgp) || fcntl (msgp[1], F_SETFD, FD_CLOEXEC)) - throw new IOException (JvNewStringUTF (strerror (errno))); + throw new IOException (JvNewStringUTF (strerror (errno))); + if (! redirect && pipe (errp)) + throw new IOException (JvNewStringUTF (strerror (errno))); // We create the streams before forking. Otherwise if we had an // error while creating the streams we would have run the child // with no way to communicate with it. - errorStream = - new FileInputStream (new - FileChannelImpl (errp[0], FileChannelImpl::READ)); - inputStream = - new FileInputStream (new - FileChannelImpl (inp[0], FileChannelImpl::READ)); - outputStream = - new FileOutputStream (new FileChannelImpl (outp[1], - FileChannelImpl::WRITE)); + if (redirect) + errorStream = PosixProcess$EOFInputStream::instance; + else + errorStream = + new FileInputStream (new + FileChannelImpl (errp[0], + FileChannelImpl::READ)); + inputStream = + new FileInputStream (new + FileChannelImpl (inp[0], FileChannelImpl::READ)); + outputStream = + new FileOutputStream (new FileChannelImpl (outp[1], + FileChannelImpl::WRITE)); // We don't use vfork() because that would cause the local // environment to be set by the child. @@ -319,14 +327,17 @@ java::lang::PosixProcess::nativeSpawn () // We ignore errors from dup2 because they should never occur. dup2 (outp[0], 0); dup2 (inp[1], 1); - dup2 (errp[1], 2); + dup2 (redirect ? inp[1] : errp[1], 2); // Use close and not myclose -- we're in the child, and we // aren't worried about the possible race condition. close (inp[0]); close (inp[1]); - close (errp[0]); - close (errp[1]); + if (! redirect) + { + close (errp[0]); + close (errp[1]); + } close (outp[0]); close (outp[1]); close (msgp[0]); @@ -362,7 +373,8 @@ java::lang::PosixProcess::nativeSpawn () myclose (outp[0]); myclose (inp[1]); - myclose (errp[1]); + if (! redirect) + myclose (errp[1]); myclose (msgp[1]); char c; @@ -406,7 +418,7 @@ java::lang::PosixProcess::nativeSpawn () { if (errorStream != NULL) errorStream->close (); - else + else if (! redirect) myclose (errp[0]); } catch (java::lang::Throwable *ignore) @@ -417,10 +429,11 @@ java::lang::PosixProcess::nativeSpawn () // the use of myclose. myclose (outp[0]); myclose (inp[1]); - myclose (errp[1]); + if (! redirect) + myclose (errp[1]); myclose (msgp[1]); - exception = thrown; + exception = thrown; } myclose (msgp[0]); @@ -430,6 +443,7 @@ java::lang::PosixProcess::nativeSpawn () { fcntl (outp[1], F_SETFD, FD_CLOEXEC); fcntl (inp[0], F_SETFD, FD_CLOEXEC); - fcntl (errp[0], F_SETFD, FD_CLOEXEC); + if (! redirect) + fcntl (errp[0], F_SETFD, FD_CLOEXEC); } } diff --git a/libjava/java/lang/natRuntime.cc b/libjava/java/lang/natRuntime.cc index 64c8fbb..02842b1 100644 --- a/libjava/java/lang/natRuntime.cc +++ b/libjava/java/lang/natRuntime.cc @@ -1,6 +1,6 @@ // natRuntime.cc - Implementation of native side of Runtime class. -/* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation +/* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation This file is part of libgcj. @@ -297,7 +297,7 @@ java::lang::Runtime::execInternal (jstringArray cmd, jstringArray env, java::io::File *dir) { - return new _Jv_platform_process (cmd, env, dir); + return new _Jv_platform_process (cmd, env, dir, false); } jint diff --git a/libjava/java/lang/natVMProcess.cc b/libjava/java/lang/natVMProcess.cc new file mode 100644 index 0000000..0a14465 --- /dev/null +++ b/libjava/java/lang/natVMProcess.cc @@ -0,0 +1,34 @@ +// natVMProcess.cc - native code for ProcessBuilder + +/* Copyright (C) 2007 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +#include <config.h> + +#include <gcj/cni.h> +#include <jvm.h> + +#include <platform.h> + +#include <java/lang/VMProcess.h> +#include <java/lang/Process.h> +#include <java/io/File.h> + +// It is convenient and safe to simply include all of these. +#include <java/lang/Win32Process.h> +#include <java/lang/EcosProcess.h> +#include <java/lang/PosixProcess.h> + +::java::lang::Process * +java::lang::VMProcess::nativeExec (jstringArray cmd, + jstringArray env, + ::java::io::File *dir, + jboolean redirect) +{ + return new _Jv_platform_process (cmd, env, dir, redirect); +} diff --git a/libjava/java/lang/natWin32Process.cc b/libjava/java/lang/natWin32Process.cc index d07f501..c836b56 100644 --- a/libjava/java/lang/natWin32Process.cc +++ b/libjava/java/lang/natWin32Process.cc @@ -1,6 +1,6 @@ // natWin32Process.cc - Native side of Win32 process code. -/* Copyright (C) 2003, 2006 Free Software Foundation +/* Copyright (C) 2003, 2006, 2007 Free Software Foundation This file is part of libgcj. @@ -210,8 +210,9 @@ HANDLE ChildProcessPipe::getChildHandle() void java::lang::Win32Process::startProcess (jstringArray progarray, - jstringArray envp, - java::io::File *dir) + jstringArray envp, + java::io::File *dir, + jboolean redirect) { using namespace java::io; |