Re: [cp-patches] FYI: Merge Thread.UncaughtExceptionHandler support from generics branch

2006-04-13 Thread Andrew John Hughes
On Wed, Apr 12, 2006 at 06:14:33PM +0200, Mark Wielaard wrote:
 Hi Archie,
 
 On Wed, 2006-04-12 at 09:10 -0500, Archie Cobbs wrote:
  Mark Wielaard wrote:
   +  /** 
   +   * p
   +   * Returns the handler used when this thread terminates due to an
   +   * uncaught exception.  The handler used is determined by the 
   following:
   +   * /p
   +   * ul
   +   * liIf this thread has its own handler, this is returned./li
   +   * liIf not, then the handler of the thread's 
   codeThreadGroup/code
   +   * object is returned./li
   +   * liIf both are unavailable, then codenull/code is 
   returned./li
   +   * /ul
   +   * 
   +   * @return the appropriate codeUncaughtExceptionHandler/code or
   +   * codenull/code if one can't be obtained.
   +   * @since 1.5 
   +   */
   +  public UncaughtExceptionHandler getUncaughtExceptionHandler()
   +  {
   +return exceptionHandler;
   +  }
  
  The Javadoc and the implementation here don't seem consistent: how
  could this ever return the thread's ThreadGroup (option #2)?
 
 Good catch. The documentation describes how VMThread handles this. But
 it looks like we can simplify that code by just doing it here as the
 documentation says.
 
 Andrew/Tom, you wrote/documented that code what do you think of this
 patch?
 
 2006-04-12  Mark Wielaard  [EMAIL PROTECTED]
 
 * java/lang/Thread.java (getUncaughtExceptionHandler): Return
 thread group when exceptionHandler isn't set.
 * vm/reference/java/lang/VMThread.java (run): Use result of
 thread.getUncaughtExceptionHandler directly.
 
 Cheers,
 
 Mark

 Index: java/lang/Thread.java
 ===
 RCS file: /cvsroot/classpath/classpath/java/lang/Thread.java,v
 retrieving revision 1.19
 diff -u -r1.19 Thread.java
 --- java/lang/Thread.java 12 Apr 2006 12:04:18 -  1.19
 +++ java/lang/Thread.java 12 Apr 2006 16:08:50 -
 @@ -1051,7 +1051,9 @@
 * liIf this thread has its own handler, this is returned./li
 * liIf not, then the handler of the thread's codeThreadGroup/code
 * object is returned./li
 -   * liIf both are unavailable, then codenull/code is returned./li
 +   * liIf both are unavailable, then codenull/code is returned
 +   * (which can only happen when the thread was terminated since
 +   *  then it won't have an associated thread group anymore)./li
 * /ul
 * 
 * @return the appropriate codeUncaughtExceptionHandler/code or
 @@ -1060,7 +1062,7 @@
 */
public UncaughtExceptionHandler getUncaughtExceptionHandler()
{
 -return exceptionHandler;
 +return exceptionHandler != null : exceptionHandler ? group;
}
  
/** 
 Index: vm/reference/java/lang/VMThread.java
 ===
 RCS file: /cvsroot/classpath/classpath/vm/reference/java/lang/VMThread.java,v
 retrieving revision 1.10
 diff -u -r1.10 VMThread.java
 --- vm/reference/java/lang/VMThread.java  12 Apr 2006 12:04:18 -  
 1.10
 +++ vm/reference/java/lang/VMThread.java  12 Apr 2006 16:08:50 -
 @@ -1,5 +1,5 @@
  /* VMThread -- VM interface for Thread of executable code
 -   Copyright (C) 2003, 2004, 2005 Free Software Foundation
 +   Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation
  
  This file is part of GNU Classpath.
  
 @@ -123,9 +123,8 @@
   {
   try
   {
 -   Thread.UncaughtExceptionHandler handler = 
 thread.getUncaughtExceptionHandler();
 -   if (handler == null)
 - handler = thread.group;
 +   Thread.UncaughtExceptionHandler handler;
 +   handler = thread.getUncaughtExceptionHandler();
 handler.uncaughtException(thread, t);
   }
   catch(Throwable ignore)



The patch certainly seems to make the code cleaner, and match the documentation
better.  IMO, it should go in, but I didn't write the original code, only 
documented
it.  They may be a reason why Tom did it like this.

This code has been hanging around for about 18 months on the generics branch.
Seems like moving these things to HEAD is doing some good... :)

Cheers,
-- 
Andrew :-)

Please avoid sending me Microsoft Office (e.g. Word, PowerPoint) attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html

If you use Microsoft Office, support movement towards the end of vendor lock-in:
http://opendocumentfellowship.org/petition/

Value your freedom, or you will lose it, teaches history. 
`Don't bother us with politics' respond those who don't want to learn. 
-- Richard Stallman

Escape the Java Trap with GNU Classpath!
http://www.gnu.org/philosophy/java-trap.html
public class gcj extends Freedom implements Java { ... }


signature.asc
Description: Digital signature


Re: [cp-patches] FYI: Merge Thread.UncaughtExceptionHandler support from generics branch

2006-04-13 Thread Tom Tromey
 Andrew == Andrew John Hughes [EMAIL PROTECTED] writes:

Andrew The patch certainly seems to make the code cleaner, and match
Andrew the documentation better.  IMO, it should go in, but I didn't
Andrew write the original code, only documented it.  They may be a
Andrew reason why Tom did it like this.

I don't remember having a reason.  I'm sure this is fine.

Tom



[cp-patches] FYI: Merge Thread.UncaughtExceptionHandler support from generics branch

2006-04-12 Thread Mark Wielaard
Hi,

One of the Debian package maintainers requested that the
Thread.UncaughtExceptionHandler support would be added to head since it
isn't dependent on any new language features. This patch does so and
documents the VMThread change needed for this in the NEWS file.

The remaining diff between the head and generics Thread file is a new
Enum and some indentation changes.

2006-04-12  Mark Wielaard  [EMAIL PROTECTED]

Port UncaughtExceptionHandler support from generics branch.
* NEWS: Document Thread.UncaughtExceptionHandler VMThread change.

2006-04-12  Andrew John Hughes  [EMAIL PROTECTED]

* java/lang/Thread.java:
(setUncaughtExceptionHandler(UncaughtExceptionHandler):
Added docs and security check.
(getUncaughtExceptionHandler()): Documented.
(setDefaultUncaughtExceptionHandler(UncaughtExceptionHandler):
Added docs and security check.
(getDefaultUncaughtExceptionHandler()): Documented.
(getId()): Documented.

2006-04-12  Tom Tromey  [EMAIL PROTECTED]

* 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.

Committed,

Mark
Index: NEWS
===
RCS file: /cvsroot/classpath/classpath/NEWS,v
retrieving revision 1.130
diff -u -r1.130 NEWS
--- NEWS	29 Mar 2006 13:10:11 -	1.130
+++ NEWS	12 Apr 2006 11:52:52 -
@@ -29,6 +29,8 @@
   now have a new native getModifiersInternal() method.  The public
   getModifiers() method in each case has been rewritten in terms of
   this method.
+* The reference implementation of VMThread has been updated to handle
+  the new Thread.UncaughtExceptionHandler support.
 
 New in release 0.90 (March 6, 2006)
 
Index: java/lang/Thread.java
===
RCS file: /cvsroot/classpath/classpath/java/lang/Thread.java,v
retrieving revision 1.18
diff -u -r1.18 Thread.java
--- java/lang/Thread.java	16 Feb 2006 09:53:13 -	1.18
+++ java/lang/Thread.java	12 Apr 2006 11:52:52 -
@@ -1,5 +1,5 @@
 /* Thread -- an independent thread of executable code
-   Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004
+   Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
Free Software Foundation
 
 This file is part of GNU Classpath.
@@ -81,6 +81,7 @@
  * @author Tom Tromey
  * @author John Keiser
  * @author Eric Blake ([EMAIL PROTECTED])
+ * @author Andrew John Hughes ([EMAIL PROTECTED])
  * @see Runnable
  * @see Runtime#exit(int)
  * @see #run()
@@ -130,15 +131,27 @@
 
   /** The context classloader for this Thread. */
   private ClassLoader contextClassLoader;
+  
+  /** This thread's ID.  */
+  private final long threadId;
 
   /** The next thread number to use. */
   private static int numAnonymousThreadsCreated;
+  
+  /** The next thread ID to use.  */
+  private static long nextThreadId;
+
+  /** The default exception handler.  */
+  private static UncaughtExceptionHandler defaultHandler;
 
   /** Thread local storage. Package accessible for use by
 * InheritableThreadLocal.
 */
   WeakIdentityHashMap locals;
 
+  /** The uncaught exception handler.  */
+  UncaughtExceptionHandler exceptionHandler;
+
   /**
* Allocates a new codeThread/code object. This constructor has
* the same effect as codeThread(null, null,/code
@@ -342,6 +355,11 @@
 this.name = name.toString();
 this.runnable = target;
 this.stacksize = size;
+
+synchronized (Thread.class)
+  {
+this.threadId = nextThreadId++;
+  }
 
 priority = current.priority;
 daemon = current.daemon;
@@ -371,6 +389,11 @@
 this.priority = priority;
 this.daemon = daemon;
 this.contextClassLoader = ClassLoader.getSystemClassLoader();
+synchronized (Thread.class)
+  {
+	this.threadId = nextThreadId++;
+  }
+
   }
 
   /**
@@ -1000,4 +1023,157 @@
   }
 return locals;
   }
+
+  /** 
+   * Assigns the given codeUncaughtExceptionHandler/code to this
+   * thread.  This will then be called if the thread terminates due
+   * to an uncaught exception, pre-empting that of the
+   * codeThreadGroup/code.
+   *
+   * @param h the handler to use for this thread.
+   * @throws SecurityException if the current thread can't modify this thread.
+   * @since 1.5 
+   */
+  public void setUncaughtExceptionHandler(UncaughtExceptionHandler h)
+  {
+SecurityManager sm = SecurityManager.current; // Be thread-safe.
+if (sm != null)
+  sm.checkAccess(this);
+exceptionHandler = h;
+  }
+
+  /** 
+   * p
+   * Returns the handler used when this thread terminates due to an
+   * uncaught 

Re: [cp-patches] FYI: Merge Thread.UncaughtExceptionHandler support from generics branch

2006-04-12 Thread Archie Cobbs

Mark Wielaard wrote:
+  /** 
+   * p

+   * Returns the handler used when this thread terminates due to an
+   * uncaught exception.  The handler used is determined by the following:
+   * /p
+   * ul
+   * liIf this thread has its own handler, this is returned./li
+   * liIf not, then the handler of the thread's codeThreadGroup/code
+   * object is returned./li
+   * liIf both are unavailable, then codenull/code is returned./li
+   * /ul
+   * 
+   * @return the appropriate codeUncaughtExceptionHandler/code or

+   * codenull/code if one can't be obtained.
+   * @since 1.5 
+   */

+  public UncaughtExceptionHandler getUncaughtExceptionHandler()
+  {
+return exceptionHandler;
+  }


The Javadoc and the implementation here don't seem consistent: how
could this ever return the thread's ThreadGroup (option #2)?

-Archie

__
Archie Cobbs  *CTO, Awarix*  http://www.awarix.com



Re: [cp-patches] FYI: Merge Thread.UncaughtExceptionHandler support from generics branch

2006-04-12 Thread Mark Wielaard
Hi Archie,

On Wed, 2006-04-12 at 09:10 -0500, Archie Cobbs wrote:
 Mark Wielaard wrote:
  +  /** 
  +   * p
  +   * Returns the handler used when this thread terminates due to an
  +   * uncaught exception.  The handler used is determined by the following:
  +   * /p
  +   * ul
  +   * liIf this thread has its own handler, this is returned./li
  +   * liIf not, then the handler of the thread's codeThreadGroup/code
  +   * object is returned./li
  +   * liIf both are unavailable, then codenull/code is returned./li
  +   * /ul
  +   * 
  +   * @return the appropriate codeUncaughtExceptionHandler/code or
  +   * codenull/code if one can't be obtained.
  +   * @since 1.5 
  +   */
  +  public UncaughtExceptionHandler getUncaughtExceptionHandler()
  +  {
  +return exceptionHandler;
  +  }
 
 The Javadoc and the implementation here don't seem consistent: how
 could this ever return the thread's ThreadGroup (option #2)?

Good catch. The documentation describes how VMThread handles this. But
it looks like we can simplify that code by just doing it here as the
documentation says.

Andrew/Tom, you wrote/documented that code what do you think of this
patch?

2006-04-12  Mark Wielaard  [EMAIL PROTECTED]

* java/lang/Thread.java (getUncaughtExceptionHandler): Return
thread group when exceptionHandler isn't set.
* vm/reference/java/lang/VMThread.java (run): Use result of
thread.getUncaughtExceptionHandler directly.

Cheers,

Mark
Index: java/lang/Thread.java
===
RCS file: /cvsroot/classpath/classpath/java/lang/Thread.java,v
retrieving revision 1.19
diff -u -r1.19 Thread.java
--- java/lang/Thread.java	12 Apr 2006 12:04:18 -	1.19
+++ java/lang/Thread.java	12 Apr 2006 16:08:50 -
@@ -1051,7 +1051,9 @@
* liIf this thread has its own handler, this is returned./li
* liIf not, then the handler of the thread's codeThreadGroup/code
* object is returned./li
-   * liIf both are unavailable, then codenull/code is returned./li
+   * liIf both are unavailable, then codenull/code is returned
+   * (which can only happen when the thread was terminated since
+   *  then it won't have an associated thread group anymore)./li
* /ul
* 
* @return the appropriate codeUncaughtExceptionHandler/code or
@@ -1060,7 +1062,7 @@
*/
   public UncaughtExceptionHandler getUncaughtExceptionHandler()
   {
-return exceptionHandler;
+return exceptionHandler != null : exceptionHandler ? group;
   }
 
   /** 
Index: vm/reference/java/lang/VMThread.java
===
RCS file: /cvsroot/classpath/classpath/vm/reference/java/lang/VMThread.java,v
retrieving revision 1.10
diff -u -r1.10 VMThread.java
--- vm/reference/java/lang/VMThread.java	12 Apr 2006 12:04:18 -	1.10
+++ vm/reference/java/lang/VMThread.java	12 Apr 2006 16:08:50 -
@@ -1,5 +1,5 @@
 /* VMThread -- VM interface for Thread of executable code
-   Copyright (C) 2003, 2004, 2005 Free Software Foundation
+   Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation
 
 This file is part of GNU Classpath.
 
@@ -123,9 +123,8 @@
 	{
 		try
 		{
-		  Thread.UncaughtExceptionHandler handler = thread.getUncaughtExceptionHandler();
-		  if (handler == null)
-		handler = thread.group;
+		  Thread.UncaughtExceptionHandler handler;
+		  handler = thread.getUncaughtExceptionHandler();
 		  handler.uncaughtException(thread, t);
 		}
 		catch(Throwable ignore)


signature.asc
Description: This is a digitally signed message part