hotspot/test/compiler/floatingpoint/TestPow2.java
author cjplummer
Thu, 29 Oct 2015 12:04:04 -0700
changeset 33730 30e064828045
parent 29678 dd2f3932c21e
child 34185 ee71c590a456
permissions -rw-r--r--
8140189: [TESTBUG] Get rid of "@library /../../test/lib" in jtreg tests Summary: Use new external.lib.roots property in TEST.ROOT so /../../test/lib is not needed. Reviewed-by: mseledtsov, sla, iklam
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
33730
30e064828045 8140189: [TESTBUG] Get rid of "@library /../../test/lib" in jtreg tests
cjplummer
parents: 29678
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;
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    39
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    40
public class TestPow2 {
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    41
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    42
    private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    43
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    44
    private static final double base = 5350.456329377186;
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    45
    private static final double exp = 2.0;
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
    static double m() {
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    48
        return Math.pow(base, exp);
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    49
    }
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
    static public void main(String[] args) throws NoSuchMethodException {
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    52
        Method test_method = TestPow2.class.getDeclaredMethod("m");
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
        double interpreter_result = m();
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    55
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    56
        // Compile with C1 if possible
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    57
        WHITE_BOX.enqueueMethodForCompilation(test_method, CompilerWhiteBoxTest.COMP_LEVEL_SIMPLE);
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    58
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    59
        double c1_result = 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
        WHITE_BOX.deoptimizeMethod(test_method);
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 it with C2 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_FULL_OPTIMIZATION);
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 c2_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
        if (interpreter_result != c1_result || interpreter_result != c2_result ||
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    69
            c1_result != c2_result) {
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    70
            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
    71
            throw new RuntimeException("Test Failed");
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
    }
d59774687206 8063086: Math.pow yields different results upon repeated calls
roland
parents:
diff changeset
    74
}