[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#404989: marked as done (gij-4.1: System.nanoTime() goes backwards)



Your message dated Mon, 23 Jul 2007 09:14:49 +0200
with message-id <18084.21865.770822.849141@gargle.gargle.HOWL>
and subject line gij-4.1: System.nanoTime() goes backwards
has caused the attached Bug report to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what I am
talking about this indicates a serious mail system misconfiguration
somewhere.  Please contact me immediately.)

Debian bug tracking system administrator
(administrator, Debian Bugs database)

--- Begin Message ---
Package: gij-4.1
Version: 4.1.1-17
Severity: normal



-- System Information:
Debian Release: 4.0
  APT prefers testing
  APT policy: (500, 'testing')
Architecture: i386 (i686)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.18-3-686
Locale: LANG=en_US, LC_CTYPE=en_US (charmap=ISO-8859-1)

Versions of packages gij-4.1 depends on:
ii  gcj-4.1-base                 4.1.1-17    The GNU Compiler Collection (gcj b
ii  libc6                        2.3.6.ds1-8 GNU C Library: Shared libraries
ii  libgcc1                      1:4.1.1-19  GCC support library
ii  libgcj7-0                    4.1.1-17    Java runtime library for use with 
ii  zlib1g                       1:1.2.3-13  compression library - runtime

gij-4.1 recommends no packages.

-- no debconf information

Sometimes System.nanoTime() reports time stamps that go backwards.

My test case is the following:

----- test case 1 -----

public class test1 {
	public static void main(String[] args) {
		long ts1;
		long ts2;

		do {
			ts1 = System.nanoTime();
			ts2 = System.nanoTime();
		} while (ts1 <= ts2);

		System.out.println("TS1: " + ts1 + ", TS2: " + ts2);
	}
}

-----------------------

1) Compile the Java source using the Sun compiler on a Debian 'unstable' system (i686).
$ javac test1.java
$
$ dpkg -l sun-java5-jdk
ii  sun-java5-jdk          1.5.0-10-1.1           Sun Java(TM) Development Kit (JDK) 5.0
$
$ java -version
java version "1.5.0_10"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_10-b03)
Java HotSpot(TM) Client VM (build 1.5.0_10-b03, mixed mode, sharing)


2) Run the program on this Debian 'testing' system (i686) using gij.
$ java -version
java version "1.4.2"
gij (GNU libgcj) version 4.1.2 20061020 (prerelease) (Debian 4.1.1-17)

Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$
$ java test1
TS1: 1516335999794, TS2: 1515337000426

This may take some seconds to show up, but it indicates that the second time stamp
is before the first time stamp.


I think System.nanoTime() is implemented on top of the C function clock_gettime() but
uses the returned information with wrong alignment (clock_gettime() returns nano-seconds
not micro-seconds). Test case:

----- test case 2 -----

public class test2 {
	public static void main(String[] args) {
		System.out.println(System.nanoTime());
	}
}

-----------------------

Compiling this program as before and using strace (strace -o /tmp/test2.strace java test2) shows:
...
...
mmap2(NULL, 12288, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb6209000
clock_gettime(CLOCK_MONOTONIC, {1515537, 182512429}) = 0
write(1, "1515719512429\n", 14)         = 14
exit_group(0)                           = ?


While clock_gettime() returns (1515537, 182512429), the System.nanoTime() gives 1515719512429.
This is an alignment error:
clock_gettime:
	1515537.000000000
	       .182512429
	-----------------
	1515537.182512429

System.nanoTime():
	   1515.537000000
	       .182512429
	-----------------
	   1515.719512429


Best regards,
-andi


--- End Message ---
--- Begin Message ---
Version: 4.1.2-14

Fixed in gij-4.1 and gij-4.2 as found in unstable.

--- End Message ---

Reply to: