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

Nondeterministic wrong answer on arithmetic

XMLWordPrintable

    • b102
    • 8
    • b53
    • generic
    • generic
    • Verified

        FULL PRODUCT VERSION :
        java version "1.8.0_31"
        Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
        Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)


        FULL OS VERSION :
        Linux laptopi 3.13.0-45-generic #74-Ubuntu SMP Tue Jan 13 19:36:28 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
        Linux thinkpad 3.18.5-1-ARCH #1 SMP PREEMPT Fri Jan 30 07:31:50 CET 2015 x86_64 GNU/Linux


        A DESCRIPTION OF THE PROBLEM :
        A code containing only simple arithmetic (generated using deterministic pseudorandom) randomly gives different results, even though it should be deterministic.


        THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: No

        THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Yes

        REGRESSION. Last worked in version 7u75

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        1. Save the code as code.java
        2. Compile the code
            $ javac code.java
        3. Run the code repeatedly, observing the changes in output, for example
            $ for i in {1..100}; do java code | sha256sum; done


        EXPECTED VERSUS ACTUAL BEHAVIOR :
        All the invocations of "java code" should output the same output with sha256 hash 629dbc538b4aa4fd16ecaefbf9cfcba1fe5910aec75740a84583dda03f044838.

        However, actual result contains many different outputs, like
        629dbc538b4aa4fd16ecaefbf9cfcba1fe5910aec75740a84583dda03f044838 -
        0f2175f5f25089d63426ccf42b4e082cb51ad760c5a8534c764f8792c0ca46f4 -
        c4a0bf7126460fd6ee02999121ec9a2d90c05b9bf27070d78de9a7605b4694e6 -
        dc66d58743810f6a000d1ab4694b98eac85dcb4dffd99dfd43a6260b508ab007 -
        629dbc538b4aa4fd16ecaefbf9cfcba1fe5910aec75740a84583dda03f044838 -
        629dbc538b4aa4fd16ecaefbf9cfcba1fe5910aec75740a84583dda03f044838 -
        629dbc538b4aa4fd16ecaefbf9cfcba1fe5910aec75740a84583dda03f044838 -
        a857ae2566df12c396990cb36828d646eb34c5e548e3c7f2af91e23782c5805e -
        629dbc538b4aa4fd16ecaefbf9cfcba1fe5910aec75740a84583dda03f044838 -
        d3bb7a3e570e4a8d0a7ae1fd3e6fccad4fbe8495b56ff08fdfbde70e00f19622 -
        a82888399f7f4544e4ec230cf1b3e7b53ecc6571422b5e17b5b685ff9e655c79 -
        629dbc538b4aa4fd16ecaefbf9cfcba1fe5910aec75740a84583dda03f044838 -
        629dbc538b4aa4fd16ecaefbf9cfcba1fe5910aec75740a84583dda03f044838 -
        629dbc538b4aa4fd16ecaefbf9cfcba1fe5910aec75740a84583dda03f044838 -
        629dbc538b4aa4fd16ecaefbf9cfcba1fe5910aec75740a84583dda03f044838 -
        a857ae2566df12c396990cb36828d646eb34c5e548e3c7f2af91e23782c5805e -
        629dbc538b4aa4fd16ecaefbf9cfcba1fe5910aec75740a84583dda03f044838 -
        629dbc538b4aa4fd16ecaefbf9cfcba1fe5910aec75740a84583dda03f044838 -
        629dbc538b4aa4fd16ecaefbf9cfcba1fe5910aec75740a84583dda03f044838 -
        629dbc538b4aa4fd16ecaefbf9cfcba1fe5910aec75740a84583dda03f044838 -
        629dbc538b4aa4fd16ecaefbf9cfcba1fe5910aec75740a84583dda03f044838 -
        629dbc538b4aa4fd16ecaefbf9cfcba1fe5910aec75740a84583dda03f044838 -
        c322caa467fcdd0e70519760c123b8fcf167e6cfdf98f648316f4e729643d77b -
        629dbc538b4aa4fd16ecaefbf9cfcba1fe5910aec75740a84583dda03f044838 -
        a857ae2566df12c396990cb36828d646eb34c5e548e3c7f2af91e23782c5805e -
        629dbc538b4aa4fd16ecaefbf9cfcba1fe5910aec75740a84583dda03f044838 -
        629dbc538b4aa4fd16ecaefbf9cfcba1fe5910aec75740a84583dda03f044838 -
        629dbc538b4aa4fd16ecaefbf9cfcba1fe5910aec75740a84583dda03f044838 -
        629dbc538b4aa4fd16ecaefbf9cfcba1fe5910aec75740a84583dda03f044838 -
        9c6eb5a688d7c78b9260baac02adf4720f0590b442c7d4ce5be64c755d66b5b7 -
        629dbc538b4aa4fd16ecaefbf9cfcba1fe5910aec75740a84583dda03f044838 -
        d113cb8865e399499ae18a19bfd494b461a403fa7a5ff2fb30ad59c0ee575f91 -
        629dbc538b4aa4fd16ecaefbf9cfcba1fe5910aec75740a84583dda03f044838 -
        629dbc538b4aa4fd16ecaefbf9cfcba1fe5910aec75740a84583dda03f044838 -
        0f2175f5f25089d63426ccf42b4e082cb51ad760c5a8534c764f8792c0ca46f4 -
        629dbc538b4aa4fd16ecaefbf9cfcba1fe5910aec75740a84583dda03f044838 -
        629dbc538b4aa4fd16ecaefbf9cfcba1fe5910aec75740a84583dda03f044838 -
        629dbc538b4aa4fd16ecaefbf9cfcba1fe5910aec75740a84583dda03f044838 -
        ...
        REPRODUCIBILITY :
        This bug can be reproduced often.

        ---------- BEGIN SOURCE ----------
        import java.util.*;
        import java.io.*;
        class code {
            public static void main(String[] args) {
                Random r = new Random(42);
                int x = 0;
                StringBuilder sb = new StringBuilder();
                for(int i = 0; i < 1000000; ++i) {
                    int v = Math.abs(r.nextInt());
                    sb.append('+').append(v).append('\n');

                    x += v;
                    while(x < 0) x += 1000000000;
                    sb.append('=').append(x).append('\n');
                }
                System.out.println(sb.toString());
            }
        }

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

        CUSTOMER SUBMITTED WORKAROUND :
        Use -Xint.

              iveresov Igor Veresov
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              14 Start watching this issue

                Created:
                Updated:
                Resolved: