hotspot/test/compiler/floatingpoint/TestPow2.java
author fyuan
Fri, 12 Aug 2016 14:36:14 +0800
changeset 40270 738587047b89
parent 40059 c2304140ed64
child 40631 ed82623d7831
permissions -rw-r--r--
8161340: ProblemList.txt update for sun/security/tools/keytool/autotest.sh Summary: Remove sun/security/tools/keytool/autotest.sh from ProblemList.txt due to JDK-8130302 has been resolved Reviewed-by: weijun Contributed-by: John Jiang <sha.jiang@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28494
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
     1
/*
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 28494
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
28494
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
     4
 *
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
     8
 *
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    13
 * accompanied this code).
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    14
 *
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    18
 *
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    21
 * questions.
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    22
 */
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    23
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    24
/*
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    25
 * @test
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    26
 * @bug 8063086
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    27
 * @summary X^2 special case for C2 yields different result than interpreter
39438
206a712f8f16 8132920: use package in compiler testlibraries
iignatyev
parents: 38152
diff changeset
    28
 * @library /testlibrary /test/lib /
38152
80e5da81fb2c 8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents: 34185
diff changeset
    29
 * @modules java.base/jdk.internal.misc
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    30
 *          java.management
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    31
 *
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    32
 * @build compiler.floatingpoint.TestPow2
39438
206a712f8f16 8132920: use package in compiler testlibraries
iignatyev
parents: 38152
diff changeset
    33
 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
206a712f8f16 8132920: use package in compiler testlibraries
iignatyev
parents: 38152
diff changeset
    34
 *                                sun.hotspot.WhiteBox$WhiteBoxPermission
28494
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    35
 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    36
 *                   -XX:-BackgroundCompilation -XX:-UseOnStackReplacement
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    37
 *                   compiler.floatingpoint.TestPow2
28494
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    38
 */
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    39
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    40
package compiler.floatingpoint;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    41
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    42
import compiler.whitebox.CompilerWhiteBoxTest;
28494
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    43
import sun.hotspot.WhiteBox;
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    44
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    45
import java.lang.reflect.Method;
28494
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    46
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    47
public class TestPow2 {
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    48
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    49
    private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    50
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    51
    private static final double base = 5350.456329377186;
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    52
    private static final double exp = 2.0;
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    53
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    54
    static double m() {
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    55
        return Math.pow(base, exp);
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    56
    }
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    57
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    58
    static public void main(String[] args) throws NoSuchMethodException {
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    59
        Method test_method = TestPow2.class.getDeclaredMethod("m");
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    60
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    61
        double interpreter_result = m();
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    62
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    63
        // Compile with C1 if possible
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    64
        WHITE_BOX.enqueueMethodForCompilation(test_method, CompilerWhiteBoxTest.COMP_LEVEL_SIMPLE);
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    65
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    66
        double c1_result = m();
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    67
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    68
        WHITE_BOX.deoptimizeMethod(test_method);
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    69
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    70
        // Compile it with C2 if possible
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    71
        WHITE_BOX.enqueueMethodForCompilation(test_method, CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION);
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    72
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    73
        double c2_result = m();
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    74
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    75
        if (interpreter_result != c1_result || interpreter_result != c2_result ||
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    76
            c1_result != c2_result) {
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    77
            System.out.println("interpreter = " + interpreter_result + " c1 = " + c1_result + " c2 = " + c2_result);
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    78
            throw new RuntimeException("Test Failed");
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    79
        }
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    80
    }
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    81
}