This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

rmi/rmic/CompilerProcess.java


CompilerProcess has a race condition whereby it can hang during
compilation.  This happens because the child process is writing to
stderr when it blocks; the parent process is reading from stdout.

4.0 branch only.

Andrew.


2005-11-08  Andrew Haley  <aph@redhat.com>

	* gnu/java/rmi/rmic/CompilerProcess.java: Use a new thread to
	handle stdout from the child process.

Index: libjava/gnu/java/rmi/rmic/CompilerProcess.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/rmi/rmic/CompilerProcess.java,v
retrieving revision 1.4
diff -u -r1.4 CompilerProcess.java
--- libjava/gnu/java/rmi/rmic/CompilerProcess.java	31 May 2004 09:17:33 -0000	1.4
+++ libjava/gnu/java/rmi/rmic/CompilerProcess.java	8 Nov 2005 09:25:15 -0000
@@ -89,10 +89,27 @@
     String[] args = computeArguments (name);
     Process p = Runtime.getRuntime ().exec (args);
 
-    /* Print compiler output to System.out. */
-    InputStream procin = p.getInputStream();
-    for (int ch = procin.read(); ch != -1; ch = procin.read())
-      System.out.print((char) ch);
+    /* Print compiler output to System.out.  Do this asynchronously so
+       that the compiler never blocks writing to its stdout.  */
+    {
+      final InputStream procin = p.getInputStream();
+      final Thread copier = new Thread() 
+	{
+	  public void run()
+	  {
+	    try
+	      {
+		for (int ch = procin.read(); ch != -1; ch = procin.read())
+		  System.out.print((char) ch);
+	      }
+	    catch (java.io.IOException _)
+	      {
+	      }
+	  }
+	};
+
+      copier.start();
+    }
 
     /* Collect compiler error output in a buffer.
      * If compilation fails, it will be used for an error message.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]