From nobody@FreeBSD.org  Wed Mar  8 11:26:59 2006
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id C4A6616A420
	for <freebsd-gnats-submit@FreeBSD.org>; Wed,  8 Mar 2006 11:26:59 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 51A8043D53
	for <freebsd-gnats-submit@FreeBSD.org>; Wed,  8 Mar 2006 11:26:59 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id k28BQxRs095390
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 8 Mar 2006 11:26:59 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id k28BQxWq095376;
	Wed, 8 Mar 2006 11:26:59 GMT
	(envelope-from nobody)
Message-Id: <200603081126.k28BQxWq095376@www.freebsd.org>
Date: Wed, 8 Mar 2006 11:26:59 GMT
From: Peter Edwards <peadar@FreeBSD.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Timing bug affecting java.lang.Object.wait(long millis)
X-Send-Pr-Version: www-2.3

>Number:         94223
>Category:       java
>Synopsis:       Timing bug affecting java.lang.Object.wait(long millis)
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    glewis
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Mar 08 11:30:04 GMT 2006
>Closed-Date:    Wed Apr 12 15:09:21 GMT 2006
>Last-Modified:  Wed Apr 12 15:09:21 GMT 2006
>Originator:     Peter Edwards
>Release:        -stable, -current
>Organization:
FreeBSD
>Environment:
FreeBSD caveman.vordel.com 6.0-STABLE FreeBSD 6.0-STABLE #1: Thu Feb  2 14:58:08 GMT 2006     petere@caveman.vordel.com:/usr/obj/usr/6-STABLE/src/sys/CAVEMAN  i386

>Description:
There's a bug in compute_abstime in hotspot/src/os/bsd/vm/os_bsd.hpp: when normalising a "struct timespec", and incrementing the seconds due to overflow of nanoseconds, the nanoseconds count is incorrectly adjusted, sometimes leading to a ~1 second overestimate of the amount of time to sleep for.

This affects java.lang.Object.wait(long millis) at a minimum.
>How-To-Repeat:
$ cat > T.java << .
> public class T {
>     public static void main(String[] args) {
>         try {
>             T t = new T();
>             t.run();
>         }
>         catch (Exception e) {
>             e.printStackTrace();
>         }
>     }
> 
>     synchronized void run() throws InterruptedException {
>         long then = System.currentTimeMillis();
>         for (;;) {
>             wait(100);
>             long now = System.currentTimeMillis();
>             System.out.println("diff: " + (now - then) + "\t(abs " + now + ")");
>             then = now;
>         }
>     }
> }
> .
$ /usr/local/jdk1.5.0/bin/javac T
$ /usr/local/jdk1.5.0/bin/java T
diff: 101       (abs 1141816614685)
diff: 103       (abs 1141816614788)
diff: 102       (abs 1141816614890)
diff: 102       (abs 1141816614992)
diff: 1009      (abs 1141816616001)
diff: 102       (abs 1141816616103)
diff: 102       (abs 1141816616205)
diff: 102       (abs 1141816616307)
diff: 102       (abs 1141816616409)
diff: 102       (abs 1141816616511)
diff: 102       (abs 1141816616613)
diff: 102       (abs 1141816616715)
diff: 102       (abs 1141816616817)
diff: 102       (abs 1141816616919)
diff: 1082      (abs 1141816618001)
diff: 102       (abs 1141816618103)
diff: 102       (abs 1141816618205)
diff: 102       (abs 1141816618307)
diff: 102       (abs 1141816618409)
diff: 105       (abs 1141816618514)
diff: 102       (abs 1141816618616)
diff: 102       (abs 1141816618718)
diff: 102       (abs 1141816618820)
diff: 102       (abs 1141816618922)
diff: 1079      (abs 1141816620001)



>Fix:
os_bsd.hpp, line 351: this:

      if (nsec >= 1000000000) {
        abstime->tv_sec += 1;
        nsec -= 1000000;
      }

should be this:

      if (nsec >= 1000000000) {
        abstime->tv_sec += 1;
        nsec -= 1000000000;
      }


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-java->glewis 
Responsible-Changed-By: glewis 
Responsible-Changed-When: Wed Mar 8 18:25:35 UTC 2006 
Responsible-Changed-Why:  
I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=94223 
State-Changed-From-To: open->closed 
State-Changed-By: glewis 
State-Changed-When: Wed Apr 12 15:08:28 UTC 2006 
State-Changed-Why:  
The submitted patch was committed to the java repository and is available 
as part of the recent patchset 3 release.  Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=94223 
>Unformatted:
