Thread.java: Reordered fields...

2004-02-05  Michael Koch  <konqueror@gmx.de>

	* java/lang/Thread.java: Reordered fields, reformated much code,
	no functional changes, some variables renamed, javadoc comments
	merged.

From-SVN: r77322
This commit is contained in:
Michael Koch 2004-02-05 16:34:30 +00:00 committed by Michael Koch
parent 6d0c7d7b6a
commit 5ad136540e
2 changed files with 107 additions and 86 deletions

View File

@ -1,3 +1,9 @@
2004-02-05 Michael Koch <konqueror@gmx.de>
* java/lang/Thread.java: Reordered fields, reformated much code,
no functional changes, some variables renamed, javadoc comments
merged.
2004-02-05 Michael Koch <konqueror@gmx.de> 2004-02-05 Michael Koch <konqueror@gmx.de>
* java/util/zip/Deflater.java, * java/util/zip/Deflater.java,

View File

@ -89,14 +89,42 @@ import gnu.gcj.RawData;
*/ */
public class Thread implements Runnable public class Thread implements Runnable
{ {
/** The maximum priority for a Thread. */
public final static int MAX_PRIORITY = 10;
/** The minimum priority for a Thread. */ /** The minimum priority for a Thread. */
public final static int MIN_PRIORITY = 1; public static final int MIN_PRIORITY = 1;
/** The priority a Thread gets by default. */ /** The priority a Thread gets by default. */
public final static int NORM_PRIORITY = 5; public static final int NORM_PRIORITY = 5;
/** The maximum priority for a Thread. */
public static final int MAX_PRIORITY = 10;
/**
* The group this thread belongs to. This is set to null by
* ThreadGroup.removeThread when the thread dies.
*/
ThreadGroup group;
/** The thread name, non-null. */
String name;
/** The object to run(), null if this is the target. */
private Runnable runnable;
/** The thread priority, 1 to 10. */
private int priority;
private boolean daemon_flag;
boolean interrupt_flag;
private boolean alive_flag;
private boolean startable_flag;
private ClassLoader context_class_loader;
// This describes the top-most interpreter frame for this thread.
RawData interp_frame;
// Our native data - points to an instance of struct natThread.
private Object data;
/** /**
* Get the number of active threads in the current Thread's ThreadGroup. * Get the number of active threads in the current Thread's ThreadGroup.
@ -106,7 +134,7 @@ public class Thread implements Runnable
* @return the number of active threads in the current ThreadGroup * @return the number of active threads in the current ThreadGroup
* @see ThreadGroup#activeCount() * @see ThreadGroup#activeCount()
*/ */
public static int activeCount () public static int activeCount()
{ {
return currentThread().getThreadGroup().activeCount(); return currentThread().getThreadGroup().activeCount();
} }
@ -118,11 +146,11 @@ public class Thread implements Runnable
* @throws SecurityException if the current Thread cannot modify this Thread * @throws SecurityException if the current Thread cannot modify this Thread
* @see SecurityManager#checkAccess(Thread) * @see SecurityManager#checkAccess(Thread)
*/ */
public final void checkAccess () public final void checkAccess()
{ {
SecurityManager s = System.getSecurityManager(); SecurityManager sm = System.getSecurityManager();
if (s != null) if (sm != null)
s.checkAccess(this); sm.checkAccess(this);
} }
/** /**
@ -133,20 +161,20 @@ public class Thread implements Runnable
* @throws IllegalThreadStateException if this Thread is not suspended * @throws IllegalThreadStateException if this Thread is not suspended
* @deprecated pointless, since suspend is deprecated * @deprecated pointless, since suspend is deprecated
*/ */
public native int countStackFrames (); public native int countStackFrames();
/** /**
* Get the currently executing Thread. * Get the currently executing Thread.
* *
* @return the currently executing Thread * @return the currently executing Thread
*/ */
public static native Thread currentThread (); public static native Thread currentThread();
/** /**
* Originally intended to destroy this thread, this method was never * Originally intended to destroy this thread, this method was never
* implemented by Sun, and is hence a no-op. * implemented by Sun, and is hence a no-op.
*/ */
public native void destroy (); public native void destroy();
/** /**
* Print a stack trace of the current thread to stderr using the same * Print a stack trace of the current thread to stderr using the same
@ -154,9 +182,9 @@ public class Thread implements Runnable
* *
* @see Throwable#printStackTrace() * @see Throwable#printStackTrace()
*/ */
public static void dumpStack () public static void dumpStack()
{ {
(new Exception ("Stack trace")).printStackTrace (); (new Exception("Stack trace")).printStackTrace();
} }
/** /**
@ -173,9 +201,9 @@ public class Thread implements Runnable
* @see #activeCount() * @see #activeCount()
* @see SecurityManager#checkAccess(ThreadGroup) * @see SecurityManager#checkAccess(ThreadGroup)
*/ */
public static int enumerate (Thread[] threads) public static int enumerate(Thread[] array)
{ {
return currentThread().group.enumerate(threads); return currentThread().group.enumerate(array);
} }
/** /**
@ -183,7 +211,7 @@ public class Thread implements Runnable
* *
* @return this Thread's name * @return this Thread's name
*/ */
public final String getName () public final String getName()
{ {
return name; return name;
} }
@ -193,7 +221,7 @@ public class Thread implements Runnable
* *
* @return the Thread's priority * @return the Thread's priority
*/ */
public final int getPriority () public final int getPriority()
{ {
return priority; return priority;
} }
@ -204,7 +232,7 @@ public class Thread implements Runnable
* *
* @return this Thread's ThreadGroup * @return this Thread's ThreadGroup
*/ */
public final ThreadGroup getThreadGroup () public final ThreadGroup getThreadGroup()
{ {
return group; return group;
} }
@ -213,10 +241,11 @@ public class Thread implements Runnable
* Return true if this Thread holds the object's lock, false otherwise. * Return true if this Thread holds the object's lock, false otherwise.
* *
* @param obj the object to test lock ownership on. * @param obj the object to test lock ownership on.
* @return true if the current thread is currently synchronized on obj
* @throws NullPointerException if obj is null. * @throws NullPointerException if obj is null.
* @since 1.4 * @since 1.4
*/ */
public static native boolean holdsLock (Object obj); public static native boolean holdsLock(Object obj);
/** /**
* Interrupt this Thread. First, there is a security check, * Interrupt this Thread. First, there is a security check,
@ -240,7 +269,7 @@ public class Thread implements Runnable
* *
* @throws SecurityException if you cannot modify this Thread * @throws SecurityException if you cannot modify this Thread
*/ */
public native void interrupt (); public native void interrupt();
/** /**
* Determine whether the current Thread has been interrupted, and clear * Determine whether the current Thread has been interrupted, and clear
@ -249,19 +278,19 @@ public class Thread implements Runnable
* @return whether the current Thread has been interrupted * @return whether the current Thread has been interrupted
* @see #isInterrupted() * @see #isInterrupted()
*/ */
public static boolean interrupted () public static boolean interrupted()
{ {
return currentThread().isInterrupted (true); return currentThread().isInterrupted(true);
} }
/** /**
* Determine whether the given Thread has been interrupted, but leave * Determine whether the given Thread has been interrupted, but leave
* the <i>interrupted status</i> alone in the process. * the <i>interrupted status</i> alone in the process.
* *
* @return whether the current Thread has been interrupted * @return whether the Thread has been interrupted
* @see #interrupted() * @see #interrupted()
*/ */
public boolean isInterrupted () public boolean isInterrupted()
{ {
return interrupt_flag; return interrupt_flag;
} }
@ -272,7 +301,7 @@ public class Thread implements Runnable
* *
* @return whether this Thread is alive * @return whether this Thread is alive
*/ */
public final boolean isAlive () public final boolean isAlive()
{ {
return alive_flag; return alive_flag;
} }
@ -283,7 +312,7 @@ public class Thread implements Runnable
* @return whether this is a daemon Thread or not * @return whether this is a daemon Thread or not
* @see #setDaemon(boolean) * @see #setDaemon(boolean)
*/ */
public final boolean isDaemon () public final boolean isDaemon()
{ {
return daemon_flag; return daemon_flag;
} }
@ -294,9 +323,9 @@ public class Thread implements Runnable
* @throws InterruptedException if the Thread is interrupted; it's * @throws InterruptedException if the Thread is interrupted; it's
* <i>interrupted status</i> will be cleared * <i>interrupted status</i> will be cleared
*/ */
public final void join () throws InterruptedException public final void join() throws InterruptedException
{ {
join (0, 0); join(0, 0);
} }
/** /**
@ -306,9 +335,9 @@ public class Thread implements Runnable
* @throws InterruptedException if the Thread is interrupted; it's * @throws InterruptedException if the Thread is interrupted; it's
* <i>interrupted status</i> will be cleared * <i>interrupted status</i> will be cleared
*/ */
public final void join (long timeout) throws InterruptedException public final void join(long ms) throws InterruptedException
{ {
join (timeout, 0); join(ms, 0);
} }
/** /**
@ -327,18 +356,20 @@ public class Thread implements Runnable
* @throws IllegalArgumentException if ns is invalid * @throws IllegalArgumentException if ns is invalid
* @XXX A ThreadListener would be nice, to make this efficient. * @XXX A ThreadListener would be nice, to make this efficient.
*/ */
public final native void join (long timeout, int nanos) public final native void join(long ms, int ns)
throws InterruptedException; throws InterruptedException;
/** /**
* Resume a suspended thread. * Resume a suspended thread.
* *
* @see #resume() * @throws SecurityException if you cannot resume the Thread
* @see #checkAccess()
* @see #suspend()
* @deprecated pointless, since suspend is deprecated * @deprecated pointless, since suspend is deprecated
*/ */
public final native void resume (); public final native void resume();
private final native void finish_ (); private final native void finish_();
/** /**
* Determine whether the given Thread has been interrupted, but leave * Determine whether the given Thread has been interrupted, but leave
@ -347,7 +378,7 @@ public class Thread implements Runnable
* @return whether the current Thread has been interrupted * @return whether the current Thread has been interrupted
* @see #interrupted() * @see #interrupted()
*/ */
private boolean isInterrupted (boolean clear_flag) private boolean isInterrupted(boolean clear_flag)
{ {
boolean r = interrupt_flag; boolean r = interrupt_flag;
if (clear_flag && r) if (clear_flag && r)
@ -367,7 +398,7 @@ public class Thread implements Runnable
* @see #start() * @see #start()
* @see #Thread(ThreadGroup, Runnable, String) * @see #Thread(ThreadGroup, Runnable, String)
*/ */
public void run () public void run()
{ {
if (runnable != null) if (runnable != null)
runnable.run(); runnable.run();
@ -385,11 +416,11 @@ public class Thread implements Runnable
* @see #isDaemon() * @see #isDaemon()
* @see #checkAccess() * @see #checkAccess()
*/ */
public final void setDaemon (boolean status) public final void setDaemon(boolean status)
{ {
checkAccess (); checkAccess();
if (!startable_flag) if (!startable_flag)
throw new IllegalThreadStateException (); throw new IllegalThreadStateException();
daemon_flag = status; daemon_flag = status;
} }
@ -410,12 +441,12 @@ public class Thread implements Runnable
public synchronized ClassLoader getContextClassLoader() public synchronized ClassLoader getContextClassLoader()
{ {
if (context_class_loader == null) if (context_class_loader == null)
context_class_loader = ClassLoader.getSystemClassLoader (); context_class_loader = ClassLoader.getSystemClassLoader();
SecurityManager s = System.getSecurityManager(); SecurityManager sm = System.getSecurityManager();
// FIXME: we can't currently find the caller's class loader. // FIXME: we can't currently find the caller's class loader.
ClassLoader callers = null; ClassLoader callers = null;
if (s != null && callers != null) if (sm != null && callers != null)
{ {
// See if the caller's class loader is the same as or an // See if the caller's class loader is the same as or an
// ancestor of this thread's class loader. // ancestor of this thread's class loader.
@ -423,11 +454,11 @@ public class Thread implements Runnable
{ {
// FIXME: should use some internal version of getParent // FIXME: should use some internal version of getParent
// that avoids security checks. // that avoids security checks.
callers = callers.getParent (); callers = callers.getParent();
} }
if (callers != context_class_loader) if (callers != context_class_loader)
s.checkPermission (new RuntimePermission ("getClassLoader")); sm.checkPermission(new RuntimePermission("getClassLoader"));
} }
return context_class_loader; return context_class_loader;
@ -442,17 +473,17 @@ public class Thread implements Runnable
* class loader is not null or an ancestor of this thread's context class * class loader is not null or an ancestor of this thread's context class
* loader. * loader.
* *
* @return the context class loader * @param classloader the new context class loader
* @throws SecurityException when permission is denied * @throws SecurityException when permission is denied
* @see setContextClassLoader(ClassLoader) * @see getContextClassLoader()
* @since 1.2 * @since 1.2
*/ */
public synchronized void setContextClassLoader(ClassLoader cl) public synchronized void setContextClassLoader(ClassLoader classloader)
{ {
SecurityManager s = System.getSecurityManager (); SecurityManager sm = System.getSecurityManager();
if (s != null) if (sm != null)
s.checkPermission (new RuntimePermission ("setContextClassLoader")); sm.checkPermission(new RuntimePermission("setContextClassLoader"));
context_class_loader = cl; context_class_loader = classloader;
} }
/** /**
@ -463,14 +494,14 @@ public class Thread implements Runnable
* @throws NullPointerException if name is null * @throws NullPointerException if name is null
* @throws SecurityException if you cannot modify this Thread * @throws SecurityException if you cannot modify this Thread
*/ */
public final void setName (String n) public final void setName(String name)
{ {
checkAccess (); checkAccess();
// The Class Libraries book says ``threadName cannot be null''. I // The Class Libraries book says ``threadName cannot be null''. I
// take this to mean NullPointerException. // take this to mean NullPointerException.
if (n == null) if (name == null)
throw new NullPointerException (); throw new NullPointerException();
name = n; this.name = name;
} }
/** /**
@ -502,9 +533,9 @@ public class Thread implements Runnable
* @see #notify() * @see #notify()
* @see #wait(long) * @see #wait(long)
*/ */
public static void sleep (long timeout) throws InterruptedException public static void sleep(long ms) throws InterruptedException
{ {
sleep (timeout, 0); sleep(ms, 0);
} }
/** /**
@ -527,7 +558,7 @@ public class Thread implements Runnable
* @see #notify() * @see #notify()
* @see #wait(long, int) * @see #wait(long, int)
*/ */
public static native void sleep (long timeout, int nanos) public static native void sleep(long timeout, int nanos)
throws InterruptedException; throws InterruptedException;
/** /**
@ -540,7 +571,7 @@ public class Thread implements Runnable
* @throws IllegalThreadStateException if the thread has already started * @throws IllegalThreadStateException if the thread has already started
* @see #run() * @see #run()
*/ */
public native void start (); public native void start();
/** /**
* Cause this Thread to stop abnormally because of the throw of a ThreadDeath * Cause this Thread to stop abnormally because of the throw of a ThreadDeath
@ -565,11 +596,11 @@ public class Thread implements Runnable
* @see SecurityManager#checkPermission(Permission) * @see SecurityManager#checkPermission(Permission)
* @deprecated unsafe operation, try not to use * @deprecated unsafe operation, try not to use
*/ */
public final void stop () public final void stop()
{ {
// Argument doesn't matter, because this is no longer // Argument doesn't matter, because this is no longer
// supported. // supported.
stop (null); stop(null);
} }
/** /**
@ -599,7 +630,7 @@ public class Thread implements Runnable
* @see SecurityManager#checkPermission(Permission) * @see SecurityManager#checkPermission(Permission)
* @deprecated unsafe operation, try not to use * @deprecated unsafe operation, try not to use
*/ */
public final native void stop (Throwable e); public final native void stop(Throwable e);
/** /**
* Suspend this Thread. It will not come back, ever, unless it is resumed. * Suspend this Thread. It will not come back, ever, unless it is resumed.
@ -613,7 +644,7 @@ public class Thread implements Runnable
* @see #resume() * @see #resume()
* @deprecated unsafe operation, try not to use * @deprecated unsafe operation, try not to use
*/ */
public final native void suspend (); public final native void suspend();
private final native void initialize_native (); private final native void initialize_native ();
@ -861,12 +892,12 @@ public class Thread implements Runnable
* Returns a string representation of this thread, including the * Returns a string representation of this thread, including the
* thread's name, priority, and thread group. * thread's name, priority, and thread group.
* *
* @return a string representation of this thread. * @return a human-readable String representing this Thread
*/ */
public String toString () public String toString()
{ {
return "Thread[" + name + "," + priority + "," + return ("Thread[" + name + "," + priority + ","
(group == null ? "" : group.getName()) + "]"; + (group == null ? "" : group.getName()) + "]");
} }
/** /**
@ -875,20 +906,4 @@ public class Thread implements Runnable
*/ */
public static native void yield (); public static native void yield ();
// Private data.
ThreadGroup group;
String name;
private Runnable runnable;
private int priority;
private boolean daemon_flag;
boolean interrupt_flag;
private boolean alive_flag;
private boolean startable_flag;
private ClassLoader context_class_loader;
// This describes the top-most interpreter frame for this thread.
RawData interp_frame;
// Our native data - points to an instance of struct natThread.
private Object data;
} }