classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] [generics] Patch: FYI: thread updates


From: Tom Tromey
Subject: [cp-patches] [generics] Patch: FYI: thread updates
Date: 20 Apr 2005 14:38:42 -0600
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50

I'm checking this in on the generics branch.

This adds UncaughtExceptionHandler and updates its users.

Tom

2005-04-19  Tom Tromey  <address@hidden>

        * vm/reference/java/lang/VMThread.java (run): Use thread's
        uncaught handler.
        * java/lang/Thread.java (defaultHandler): New field.
        (setDefaultUncaughtExceptionHandler,
        getDefaultUncaughtExceptionHandler, setUncaughtExceptionHandler,
        getUncaughtExceptionHandler): New methods.
        * java/lang/ThreadGroup.java (ThreadGroup): Implements
        UncaughtExceptionHandler.
        (uncaughtException): Use getDefaultUncaughtExceptionHandler.

Index: java/lang/Thread.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/lang/Thread.java,v
retrieving revision 1.8.2.6
diff -u -r1.8.2.6 Thread.java
--- java/lang/Thread.java 21 Mar 2005 12:10:17 -0000 1.8.2.6
+++ java/lang/Thread.java 20 Apr 2005 20:15:29 -0000
@@ -134,11 +134,17 @@
   /** The next thread number to use. */
   private static int numAnonymousThreadsCreated;
 
+  /** The default exception handler.  */
+  private static UncaughtExceptionHandler defaultHandler;
+
   /** Thread local storage. Package accessible for use by
     * InheritableThreadLocal.
     */
   WeakHashMap locals;
 
+  /** The uncaught exception handler.  */
+  UncaughtExceptionHandler exceptionHandler;
+
   /**
    * Allocates a new <code>Thread</code> object. This constructor has
    * the same effect as <code>Thread(null, null,</code>
@@ -330,12 +336,12 @@
     if (group == null)
       {
        if (sm != null)
-           group = sm.getThreadGroup();
+         group = sm.getThreadGroup();
        if (group == null)
-           group = current.group;
+         group = current.group;
       }
     else if (sm != null)
-       sm.checkAccess(group);
+      sm.checkAccess(group);
 
     this.group = group;
     // Use toString hack to detect null.
@@ -366,7 +372,7 @@
     this.vmThread = vmThread;
     this.runnable = null;
     if (name == null)
-       name = "Thread-" + ++numAnonymousThreadsCreated;
+      name = "Thread-" + ++numAnonymousThreadsCreated;
     this.name = name;
     this.priority = priority;
     this.daemon = daemon;
@@ -413,7 +419,7 @@
   {
     VMThread t = vmThread;
     if (t == null || group == null)
-       throw new IllegalThreadStateException();
+      throw new IllegalThreadStateException();
 
     return t.countStackFrames();
   }
@@ -557,7 +563,7 @@
     checkAccess();
     VMThread t = vmThread;
     if (t != null)
-       t.interrupt();
+      t.interrupt();
   }
 
   /**
@@ -648,12 +654,12 @@
    */
   public final void join(long ms, int ns) throws InterruptedException
   {
-    if(ms < 0 || ns < 0 || ns > 999999)
-       throw new IllegalArgumentException();
+    if (ms < 0 || ns < 0 || ns > 999999)
+      throw new IllegalArgumentException();
 
     VMThread t = vmThread;
-    if(t != null)
-        t.join(ms, ns);
+    if (t != null)
+      t.join(ms, ns);
   }
 
   /**
@@ -671,7 +677,7 @@
     checkAccess();
     VMThread t = vmThread;
     if (t != null)
-       t.resume();
+      t.resume();
   }
   
   /**
@@ -768,9 +774,9 @@
       throw new NullPointerException();
     VMThread t = vmThread;
     if (t != null)
-       t.setName(name);
+      t.setName(name);
     else
-       this.name = name;
+      this.name = name;
   }
 
   /**
@@ -824,7 +830,6 @@
    */
   public static void sleep(long ms, int ns) throws InterruptedException
   {
-
     // Check parameters
     if (ms < 0 || ns < 0 || ns > 999999)
       throw new IllegalArgumentException();
@@ -846,7 +851,7 @@
   public synchronized void start()
   {
     if (vmThread != null || group == null)
-       throw new IllegalThreadStateException();
+      throw new IllegalThreadStateException();
 
     VMThread.create(this, stacksize);
   }
@@ -943,7 +948,7 @@
     checkAccess();
     VMThread t = vmThread;
     if (t != null)
-       t.suspend();
+      t.suspend();
   }
 
   /**
@@ -970,9 +975,9 @@
     priority = Math.min(priority, group.getMaxPriority());
     VMThread t = vmThread;
     if (t != null)
-       t.setPriority(priority);
+      t.setPriority(priority);
     else
-       this.priority = priority;
+      this.priority = priority;
   }
 
   /**
@@ -1011,6 +1016,30 @@
     return locals;
   }
 
+  /** @since 1.5 */
+  public void setUncaughtExceptionHandler(UncaughtExceptionHandler h)
+  {
+    exceptionHandler = h;
+  }
+
+  /** @since 1.5 */
+  public UncaughtExceptionHandler getUncaughtExceptionHandler()
+  {
+    return exceptionHandler;
+  }
+
+  /** @since 1.5 */
+  public static void 
setDefaultUncaughtExceptionHandler(UncaughtExceptionHandler h)
+  {
+    defaultHandler = h;
+  }
+
+  /** @since 1.5 */
+  public static UncaughtExceptionHandler getDefaultUncaughtExceptionHandler()
+  {
+    return defaultHandler;
+  }
+
   /**
    * <p>
    * This interface is used to handle uncaught exceptions
@@ -1055,7 +1084,7 @@
    * @see
    * 
Thread#setDefaultUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler)
    */
-  public static interface UncaughtExceptionHandler
+  public interface UncaughtExceptionHandler
   {
     /**
      * Invoked by the virtual machine with the dying thread
@@ -1069,6 +1098,7 @@
     void uncaughtException(Thread thr, Throwable exc);
   }
 
+  /** @since 1.5 */
   public enum State
   {
     BLOCKED, NEW, RUNNABLE, TERMINATED, TIMED_WAITING, WAITING;
@@ -1078,5 +1108,4 @@
      */
     private static final long serialVersionUID = 605505746047245783L;
   }
-
 }
Index: java/lang/ThreadGroup.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/lang/ThreadGroup.java,v
retrieving revision 1.16.2.2
diff -u -r1.16.2.2 ThreadGroup.java
--- java/lang/ThreadGroup.java 19 Feb 2005 10:50:37 -0000 1.16.2.2
+++ java/lang/ThreadGroup.java 20 Apr 2005 20:15:29 -0000
@@ -37,6 +37,7 @@
 
 package java.lang;
 
+import java.lang.Thread.UncaughtExceptionHandler;
 import java.util.Vector;
 
 /**
@@ -53,7 +54,7 @@
  * @since 1.0
  * @status updated to 1.4
  */
-public class ThreadGroup
+public class ThreadGroup implements UncaughtExceptionHandler
 {
   /** The Initial, top-level ThreadGroup. */
   static ThreadGroup root = new ThreadGroup();
@@ -545,6 +546,8 @@
   {
     if (parent != null)
       parent.uncaughtException(thread, t);
+    else if (Thread.getDefaultUncaughtExceptionHandler() != null)
+      Thread.getDefaultUncaughtExceptionHandler().uncaughtException(thread, t);
     else if (! (t instanceof ThreadDeath))
       {
         if (t == null)
Index: vm/reference/java/lang/VMThread.java
===================================================================
RCS file: /cvsroot/classpath/classpath/vm/reference/java/lang/VMThread.java,v
retrieving revision 1.2.2.1
diff -u -r1.2.2.1 VMThread.java
--- vm/reference/java/lang/VMThread.java 16 Jan 2005 15:15:15 -0000 1.2.2.1
+++ vm/reference/java/lang/VMThread.java 20 Apr 2005 20:15:34 -0000
@@ -118,7 +118,10 @@
            {
                try
                {
-                   thread.group.uncaughtException(thread, t);
+                 Thread.UncaughtExceptionHandler handler = 
thread.getUncaughtExceptionHandler();
+                 if (handler == null)
+                   handler = thread.group;
+                 handler.uncaughtException(thread, t);
                }
                catch(Throwable ignore)
                {




reply via email to

[Prev in Thread] Current Thread [Next in Thread]