[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [cp-patches] RFC: VMThread.sleep mauve fix
From: |
Christian Thalinger |
Subject: |
Re: [cp-patches] RFC: VMThread.sleep mauve fix |
Date: |
Tue, 01 Nov 2005 19:21:41 +0100 |
On Tue, 2005-11-01 at 18:31 +0100, Mark Wielaard wrote:
> The round up probably comes from join() which uses a similar way to
> wait. And according to the bug pointed to in the comment apparently some
> VMs mishandle a zero ms argument (we also had that bug in the past).
It seems that sun also does some rounding in join. With ns >= 500000
you get an:
java.lang.IllegalArgumentException: timeout value is negative
Maybe we should also behave like this and write some mauve tests for?
> Should we add a ns = 0 after wait() returns here? Whether or not you
> think that change is necessary, please feel free to commit this.
Yes, i already thought about that. I'll commit the patch like this:
Index: vm/reference/java/lang/VMThread.java
===================================================================
RCS file: /cvsroot/classpath/classpath/vm/reference/java/lang/VMThread.java,v
retrieving revision 1.8
diff -u -3 -p -r1.8 VMThread.java
--- vm/reference/java/lang/VMThread.java 2 Jul 2005 20:33:08 -0000
1.8
+++ vm/reference/java/lang/VMThread.java 1 Nov 2005 18:17:46 -0000
@@ -376,15 +376,11 @@ final class VMThread
*/
static void sleep(long ms, int ns) throws InterruptedException
{
-
- // Round up
- ms += (ns != 0) ? 1 : 0;
-
// Note: JDK treats a zero length sleep is like Thread.yield(),
// without checking the interrupted status of the thread.
// It's unclear if this is a bug in the implementation or the spec.
// See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6213203
- if (ms == 0)
+ if (ms == 0 && ns == 0)
{
if (Thread.interrupted())
throw new InterruptedException();
@@ -404,11 +400,12 @@ final class VMThread
{
while (true)
{
- vt.wait(ms);
+ vt.wait(ms, ns);
now = System.currentTimeMillis();
if (now >= end)
break;
ms = end - now;
+ ns = 0;
}
}
}