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]

RFA PATCH: Fix PosixProcess some more...


My recent changes to PosixProcess cause it to fail when GC happens while
a Process is executing.

On a glibc-2.2.5/linuxthreads system the symptoms are that all threads
are frozen in GC until the Process terminates.

On my Fedora Core 1 NPTL system, GC seems to work, but the process
reaper thread gets killed causing other types of bad behavior.

The attach patch seems to fix the problmes.

Tested with make check in libjava with no regressions on:

i686-pc-linux-gnu (Fedora Core 1 NPTL) and mipsel-linux-gnu (glibc
2.2.5) with no regressions.

OK to commit?

David Daney
2004-08-17  David Daney  <ddaney@avtrex.com>

	* java/lang/natPosixProcess.cc (waitForSignal): Use sigsuspend
	instead of sigwait.

Index: java/lang/natPosixProcess.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natPosixProcess.cc,v
retrieving revision 1.19
diff -c -p -r1.19 natPosixProcess.cc
*** java/lang/natPosixProcess.cc	12 Aug 2004 16:20:11 -0000	1.19
--- java/lang/natPosixProcess.cc	17 Aug 2004 19:27:39 -0000
*************** java::lang::ConcreteProcess$ProcessManag
*** 128,149 ****
  {
    using namespace java::lang;
  
!   sigset_t mask;
    // Wait for SIGCHLD
    sigemptyset (&mask);
!   sigaddset (&mask, SIGCHLD);
  
!   int sig;
!   int c = sigwait (&mask, &sig);
  
!   if (c != 0)
      goto error;
  
    // All OK.
    return;
  
  error:
!   throw new InternalError (JvNewStringUTF (strerror (c)));
  }
  
  jboolean java::lang::ConcreteProcess$ProcessManager::reap ()
--- 128,151 ----
  {
    using namespace java::lang;
  
!   sigset_t mask, new_mask;
    // Wait for SIGCHLD
    sigemptyset (&mask);
!   pthread_sigmask (SIG_BLOCK, &mask, &new_mask);
!   sigdelset (&new_mask, SIGCHLD);
  
!   int c = sigsuspend (&new_mask);
  
!   if (c != -1)
!     goto error;
!   if (errno != EINTR)
      goto error;
  
    // All OK.
    return;
  
  error:
!   throw new InternalError (JvNewStringUTF (strerror (errno)));
  }
  
  jboolean java::lang::ConcreteProcess$ProcessManager::reap ()
2004-08-17  David Daney  <ddaney@avtrex.com>

	* testsuite/libjava.lang/Process_7.java: New test.
	* testsuite/libjava.lang/Process_7.out: Expected output.

Index: testsuite/libjava.lang/Process_7.java
===================================================================
RCS file: testsuite/libjava.lang/Process_7.java
diff -N testsuite/libjava.lang/Process_7.java
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/libjava.lang/Process_7.java	17 Aug 2004 19:35:18 -0000
***************
*** 0 ****
--- 1,50 ----
+ // Create a long running Process.  Verify that the garbage collector
+ // can run and that it does not interfere with the Process.
+ public class Process_7 implements Runnable
+ {
+   public void run()
+   {
+     try
+       {
+         Runtime r = Runtime.getRuntime();
+         String[] a = { "sleep", "30"};
+         Process p = r.exec(a);
+         int rc = p.waitFor();
+         if(rc == 0)
+           System.out.println("ok");
+         else
+           System.out.println("bad 1");
+       }
+     catch (Exception ex)
+       {
+         ex.printStackTrace();
+       }
+   }
+ 
+   public static void main(String args[])
+   {
+     try
+       {
+         Process_7 p = new Process_7();
+         Thread t = new Thread(p);
+         t.start();
+         long elapsed = 0;
+         for (int i = 0; i < 30; i++)
+           {
+             Thread.sleep(1000);
+             long s = System.currentTimeMillis();
+             System.gc();
+             long e = System.currentTimeMillis();
+             elapsed += (e - s);
+           }
+         if (elapsed > 15000)
+           System.out.println("bad 2");
+         else
+           System.out.println("ok");
+       }
+     catch (Exception ex)
+       {
+         ex.printStackTrace();
+       }
+   }
+ }
Index: testsuite/libjava.lang/Process_7.out
===================================================================
RCS file: testsuite/libjava.lang/Process_7.out
diff -N testsuite/libjava.lang/Process_7.out
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/libjava.lang/Process_7.out	17 Aug 2004 19:35:18 -0000
***************
*** 0 ****
--- 1,2 ----
+ ok
+ ok

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