hotspot/test/compiler/floatingpoint/TestPow2.java
author chegar
Tue, 22 Mar 2016 15:26:07 +0000
changeset 36694 182a5e7a519e
parent 34185 ee71c590a456
child 38152 80e5da81fb2c
permissions -rw-r--r--
Merge
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
34185
neliasso
parents: 33730 34155
diff changeset
    28
 * @library /testlibrary /test/lib /compiler/whitebox /
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 28494
diff changeset
    29
 * @modules java.management
28494
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    30
 * @build TestPow2
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    31
 * @run main ClassFileInstaller sun.hotspot.WhiteBox
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    32
 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    33
 *                   -XX:-BackgroundCompilation -XX:-UseOnStackReplacement TestPow2
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    34
 *
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    35
 */
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    36
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    37
import java.lang.reflect.*;
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    38
import sun.hotspot.WhiteBox;
34155
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents: 29678
diff changeset
    39
import compiler.whitebox.CompilerWhiteBoxTest;
28494
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    40
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    41
public class TestPow2 {
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    42
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    43
    private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    44
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    45
    private static final double base = 5350.456329377186;
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    46
    private static final double exp = 2.0;
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    47
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    48
    static double m() {
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    49
        return Math.pow(base, exp);
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
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    52
    static public void main(String[] args) throws NoSuchMethodException {
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    53
        Method test_method = TestPow2.class.getDeclaredMethod("m");
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    54
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    55
        double interpreter_result = m();
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
        // Compile with C1 if possible
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    58
        WHITE_BOX.enqueueMethodForCompilation(test_method, CompilerWhiteBoxTest.COMP_LEVEL_SIMPLE);
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    59
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    60
        double c1_result = m();
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    61
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    62
        WHITE_BOX.deoptimizeMethod(test_method);
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    63
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    64
        // Compile it with C2 if possible
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    65
        WHITE_BOX.enqueueMethodForCompilation(test_method, CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION);
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    66
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    67
        double c2_result = m();
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    68
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    69
        if (interpreter_result != c1_result || interpreter_result != c2_result ||
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    70
            c1_result != c2_result) {
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    71
            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
    72
            throw new RuntimeException("Test Failed");
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    73
        }
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
}