Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8267445

The time interval obtained with nanoTime in jdk9 is negative

XMLWordPrintable

    • x86_64
    • generic

      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


            thartmann Tobias Hartmann
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: