Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 8 Mar 2006 11:26:59 GMT
From:      Peter Edwards <peadar@FreeBSD.org>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   java/94223: Timing bug affecting java.lang.Object.wait(long millis)
Message-ID:  <200603081126.k28BQxWq095376@www.freebsd.org>
Resent-Message-ID: <200603081130.k28BU4Kk021536@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         94223
>Category:       java
>Synopsis:       Timing bug affecting java.lang.Object.wait(long millis)
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-java
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Mar 08 11:30:04 GMT 2006
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200603081126.k28BQxWq095376>