JDK-8267445 : The time interval obtained with nanoTime in jdk9 is negative
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 9
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: x86_64
  • Submitted: 2021-05-09
  • Updated: 2021-05-21
  • Resolved: 2021-05-21
Related Reports
Duplicate :  
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
The bug can be triggered at both macOS and Ubuntu.
More detailed:
Linux:
Ubuntu 18.04.2 LTS
CPU model: Intel(R) Xeon(R) CPU E5-2620 v4 @ 2.10GHz
CPU cores: two octa-core CPUs
Memory: 96452 MB
macOS:
macOS Big Sur
Version 11.2.3 (20D91)
Processor 2.3 GHz Dual-Core Intel Core i5
Memory 8 GB 2133 MHz LPDDR3

Affected Version:
openjdk version ���9���
OpenJDK Runtime Environment (build 9+181)
OpenJDK 64-Bit Server VM (build 9+181, mixed mode)

A DESCRIPTION OF THE PROBLEM :
We found that the time interval obtained with nanoTime in jdk-9 is sometimes negative. We tried to look at the source code of nanoTime, but this is a native method. So we searched the jdk bug report to see if there are related issues. We did find the related issute: https://bugs.openjdk.java.net/browse/JDK-8184271. In this iusse, the bugs on JDK8 and JDK10 have been fixed, and we downloaded all the implementations from jdk-8 to jdk-16 on the http://jdk.java.net/ and tested them. The result is that in addition to jdk-9, this bug has indeed been fixed in other versions. However, the bug in jdk-9 has not been fixed. On https://bugs.openjdk.java.net/browse/JDK-8185714. It explained: Not seen on 9 unless ISC disabled. However, this bug can still be triggered without setting any vm options under jdk-9.

REGRESSION : Last worked in version 15

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Just run the following test case on jdk-9 without setting any vm options.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
normal execute
ACTUAL -
Exception in thread "main" java.lang.RuntimeException: testNanoTime failed with -47

---------- BEGIN SOURCE ----------
public class Bug {

    public static void main(String[] var0) {

        for(int var1 = 0; var1 < 100000; ++var1) {
            testNanoTime();
        }
    }

    private static void testNanoTime() {
        long var0 = System.nanoTime();
        long var1 = System.nanoTime();
        checkNanoTime(var1 - var0);
    }

    private static void checkNanoTime(long var0) {
        if (var0 < 0L) {
            throw new RuntimeException("testNanoTime failed with " + var0);
        }
    }
}

---------- END SOURCE ----------

FREQUENCY : always



Comments
I agree with David's analysis and close this as duplicate of JDK-8184271.
21-05-2021

The original test case for JDK-8184271 fails out-of-the-box for me on 9+181 - every time.
21-05-2021

This seems to be a request to reopen JDK-8185714 and fix this in 9u but as far as I know noone is providing 9u updates any more so it isn't likely to happen.
21-05-2021

Not able to reproduce this issue, could not get any exception for negative time. OS : Linux(Ubuntu 20.04) JDK 9+181: Pass JDK 9.0.4: Pass JDK 17ea21:Pass OS: Windows 10 JDK 9+181: Pass JDK 9.0.4: Pass JDK 17ea21:Pass Moving it to Dev team for further evaluation.
20-05-2021