hotspot/test/compiler/floatingpoint/ModNaN.java
author tpivovarova
Tue, 12 Jul 2016 18:24:48 +0300
changeset 40059 c2304140ed64
parent 35179 9e364645fdca
child 40344 e73c2f13704d
permissions -rw-r--r--
8132919: Put compiler tests in packages Reviewed-by: vlivanov, dpochepk Contributed-by: igor.ignatyev@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24319
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
     1
/*
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
     4
 *
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
     7
 * published by the Free Software Foundation.
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
     8
 *
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    13
 * accompanied this code).
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    14
 *
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    18
 *
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    21
 * questions.
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    22
 */
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    23
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    24
/**
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    25
 * @test
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    26
 * @bug 8015396
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35179
diff changeset
    27
 * @summary double a%b returns NaN for some (a,b) (|a| < inf, |b|>0) (on Core i7 980X)
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35179
diff changeset
    28
 *
35179
9e364645fdca 8145620: Disable compiler/floatingpoint/ModNaN.java
iklam
parents: 35055
diff changeset
    29
 * @ignore 8145543
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35179
diff changeset
    30
 * @run main compiler.floatingpoint.ModNaN
24319
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    31
 */
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35179
diff changeset
    32
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35179
diff changeset
    33
package compiler.floatingpoint;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35179
diff changeset
    34
24319
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    35
public class ModNaN {
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    36
    /* This bug was seen in the field for a particular version of the VM,
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    37
     * but never reproduced internally, and the reason was never known,
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    38
     * nor were the exact circumstances of the failure.
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    39
     */
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    40
    /*
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    41
     * Failed on Windows 7/Core i7 980X/1.6.0_38 (64-bit):
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    42
     *
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    43
     * NaNs (i.e., when it fails, this is what we expect to see):
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    44
     *
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    45
     * 8.98846567431158E307 % 1.295163E-318 = NaN
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    46
     * (0x7FE0000000000000L % 0x0000000000040000L)
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    47
     *
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    48
     * 1.7976931348623157E308 % 2.59032E-318 = NaN
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    49
     * (0x7FEFFFFFFFFFFFFFL % 0x000000000007FFFFL)
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    50
     *
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    51
     * 1.7976931348623157E308 % 1.060997895E-314 = NaN
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    52
     * (0x7FEFFFFFFFFFFFFFL % 0x000000007FFFFFFFL)
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    53
     *
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    54
     * 1.7976931348623157E308 % 6.767486E-317 = NaN
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    55
     * (0x7FEFFFFFFFFFFFFFL % 0x0000000000d10208L)
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    56
     *
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    57
     * 1.7976931348623157E308 % 7.528725E-318 = NaN
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    58
     * (0x7FEFFFFFFFFFFFFFL % 0x0000000000174077L)
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    59
     *
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    60
     * These cases did not fail, even when the previous five did:
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    61
     * 8.98846567431158E307 % 1.29516E-318 = 2.53E-321
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    62
     * (0x7fe0000000000000L % 0x000000000003ffffL)
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    63
     *
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    64
     * 1.7976931348623157E308 % 2.590327E-318 = 0.0
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    65
     * (0x7fefffffffffffffL % 0x0000000000080000L)
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    66
     *
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    67
     * 1.7976931348623157E308 % 1.060965516E-314 = 9.35818525E-315
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    68
     * (0x7fefffffffffffffL % 0x000000007ffeffffL)
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    69
     *
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    70
     */
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    71
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    72
    static double[][] bad = new double[][] {
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    73
            /*
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    74
             * These hex numbers correspond to the base-10 doubles in the
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    75
             * comment above; this can be checked by observing the output
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    76
             * of testWithPrint.
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    77
             */
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    78
            new double[] { Double.longBitsToDouble(0x7FE0000000000000L),
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    79
                    Double.longBitsToDouble(0x0000000000040000L) },
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    80
            new double[] { Double.longBitsToDouble(0x7FEFFFFFFFFFFFFFL),
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    81
                    Double.longBitsToDouble(0x000000000007FFFFL) },
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    82
            new double[] { Double.longBitsToDouble(0x7FEFFFFFFFFFFFFFL),
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    83
                    Double.longBitsToDouble(0x000000007FFFFFFFL) },
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    84
            new double[] { Double.longBitsToDouble(0x7FEFFFFFFFFFFFFFL),
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    85
                    6.767486E-317 },
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    86
            new double[] { Double.longBitsToDouble(0x7FEFFFFFFFFFFFFFL),
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    87
                    7.528725E-318 }, };
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    88
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    89
    static double[][] good = new double[][] {
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    90
            new double[] { Double.longBitsToDouble(0x7FE0000000000000L),
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    91
                    Double.longBitsToDouble(0x000000000003FFFFL) },
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    92
            new double[] { Double.longBitsToDouble(0x7FEFFFFFFFFFFFFFL),
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    93
                    Double.longBitsToDouble(0x0000000000080000L) },
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    94
            new double[] { Double.longBitsToDouble(0x7FEFFFFFFFFFFFFFL),
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    95
                    Double.longBitsToDouble(0x000000007FFEFFFFL) }, };
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    96
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    97
    public static void main(String[] args) throws InterruptedException {
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    98
        int N = 10000;
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    99
        testWithPrint();
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   100
        for (int i = 0; i < N; i++)
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   101
            testStrict();
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   102
        for (int i = 0; i < N; i++)
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   103
            test();
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   104
        Thread.sleep(1000); // pause to let the compiler work
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   105
        for (int i = 0; i < 10; i++)
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   106
            testStrict();
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   107
        for (int i = 0; i < 10; i++)
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   108
            test();
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   109
    }
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   110
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   111
    public strictfp static void testWithPrint() {
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   112
        for (double[] ab : bad) {
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   113
            double a = ab[0];
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   114
            double b = ab[1];
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   115
            double mod = a % b;
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   116
            System.out.println("" + a + "("+toHexRep(a)+") mod " +
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   117
                                    b + "("+toHexRep(b)+") yields " +
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   118
                                    mod + "("+toHexRep(mod)+")");
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   119
        }
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   120
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   121
        for (double[] ab : good) {
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   122
            double a = ab[0];
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   123
            double b = ab[1];
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   124
            double mod = a % b;
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   125
            System.out.println("" + a + "("+toHexRep(a)+") mod " +
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   126
                                    b + "("+toHexRep(b)+") yields " +
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   127
                                    mod + "("+toHexRep(mod)+")");
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   128
        }
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   129
    }
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   130
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   131
    public strictfp static void testStrict() {
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   132
        for (double[] ab : bad) {
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   133
            double a = ab[0];
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   134
            double b = ab[1];
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   135
            double mod = a % b;
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   136
            check(mod);
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   137
        }
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   138
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   139
        for (double[] ab : good) {
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   140
            double a = ab[0];
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   141
            double b = ab[1];
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   142
            double mod = a % b;
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   143
            check(mod);
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   144
        }
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   145
    }
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   146
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   147
    public static void test() {
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   148
        for (double[] ab : bad) {
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   149
            double a = ab[0];
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   150
            double b = ab[1];
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   151
            double mod = a % b;
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   152
            check(mod);
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   153
        }
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   154
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   155
        for (double[] ab : good) {
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   156
            double a = ab[0];
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   157
            double b = ab[1];
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   158
            double mod = a % b;
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   159
            check(mod);
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   160
        }
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   161
    }
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   162
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   163
    static String toHexRep(double d) {
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   164
        return "0x" + Long.toHexString(Double.doubleToRawLongBits(d)) + "L";
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   165
    }
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   166
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   167
    static void check(double mod) {
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   168
        if (Double.isNaN(mod)) {
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   169
            throw new Error("Saw a NaN, fail");
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   170
        }
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   171
    }
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   172
}