test/hotspot/jtreg/runtime/interpreter/WideStrictInline.java
author herrick
Fri, 19 Apr 2019 07:55:28 -0400
branchJDK-8200758-branch
changeset 57331 221a589c52ee
parent 54142 6ab293f66cae
permissions -rw-r--r--
8222676: create-installer with --app-image fails on mac Submitten-by: almatvee Reviewed-by: herrick
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48742
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
     1
/*
54142
6ab293f66cae 8219139: move hotspot tests from test/jdk/vm
iignatyev
parents: 48742
diff changeset
     2
 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
48742
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
     4
 *
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
     7
 * published by the Free Software Foundation.
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
     8
 *
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    13
 * accompanied this code).
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    14
 *
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    18
 *
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    21
 * questions.
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    22
 */
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    23
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    24
/*
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    25
 * @test
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    26
 * @bug 4169183
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    27
 * @summary Check for correct inlining by the interpreter (widefp and strictfp).
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    28
 *          The default is widefp.  A strictfp method was getting inlined
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    29
 *          into a widefp method.
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    30
 */
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    31
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    32
import java.io.PrintStream;
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    33
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    34
public class WideStrictInline {
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    35
    static PrintStream out;
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    36
    static float halfUlp;
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    37
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    38
    static {
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    39
        halfUlp = 1;
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    40
        for ( int i = 127 - 24; i > 0; i-- )
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    41
            halfUlp *= 2;
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    42
    }
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    43
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    44
    public static void main(String argv[]) throws Exception {
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    45
        out = System.err;
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    46
        pr(-1,"halfUlp",halfUlp);
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    47
        WideStrictInline obj = new WideStrictInline();
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    48
        for( int i=0; i<48; i++ )
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    49
            obj.instanceMethod( i );
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    50
    }
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    51
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    52
    private static void pr(int i, String desc, float r) {
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    53
        out.print(" i=("+i+") "+desc+" ; == "+r);
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    54
        out.println(" , 0x"+Integer.toHexString(Float.floatToIntBits(r)));
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    55
    }
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    56
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    57
    private static strictfp float WideStrictInline(float par) {
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    58
        return par;
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    59
    }
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    60
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    61
    public static strictfp float strictValue(int i) {
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    62
        float r;
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    63
        switch (i%4) {
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    64
        case 0: r = -Float.MAX_VALUE;  break;
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    65
        case 1: r =  Float.MAX_VALUE;  break;
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    66
        case 2: r =  Float.MIN_VALUE;  break;
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    67
        default : r = 1L << 24;
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    68
        }
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    69
        return r;
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    70
    }
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    71
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    72
    void instanceMethod (int i) throws Exception {
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    73
        float r;
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    74
        switch (i%4) {
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    75
        case 0:
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    76
            if (!Float.isInfinite( WideStrictInline(strictValue(i)*2) +
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    77
                                   Float.MAX_VALUE ))
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    78
                {
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    79
                    pr(i,
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    80
                       "WideStrictInline(-Float.MAX_VALUE * 2) " +
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    81
                       "!= Float.NEGATIVE_INFINITY"
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    82
                       ,WideStrictInline(strictValue(i)*2) + Float.MAX_VALUE);
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    83
                }
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    84
            r = WideStrictInline(strictValue(i)*2) + Float.MAX_VALUE;
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    85
            if ( !Float.isInfinite( r ) ) {
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    86
                pr(i,"r != Float.NEGATIVE_INFINITY",r);
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    87
                throw new RuntimeException();
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    88
            }
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    89
            break;
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    90
        case 1:
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    91
            if (!Float.isInfinite(WideStrictInline(strictValue(i)+halfUlp) -
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    92
                                  Float.MAX_VALUE )) {
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    93
                pr(i,"WideStrictInline(Float.MAX_VALUE+halfUlp) " +
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    94
                   "!= Float.POSITIVE_INFINITY"
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    95
                   ,WideStrictInline(strictValue(i)+halfUlp) - Float.MAX_VALUE);
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    96
            }
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    97
            r = WideStrictInline(strictValue(i)+halfUlp) - Float.MAX_VALUE;
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    98
            if ( !Float.isInfinite( r ) ) {
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
    99
                pr(i,"r != Float.POSITIVE_INFINITY",r);
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
   100
                throw new RuntimeException();
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
   101
            }
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
   102
            break;
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
   103
        case 2:
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
   104
            if (WideStrictInline(strictValue(i)/2) != 0) {
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
   105
                pr(i,"WideStrictInline(Float.MIN_VALUE/2) != 0",
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
   106
                   WideStrictInline(strictValue(i)/2));
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
   107
            }
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
   108
            r = WideStrictInline(strictValue(i)/2);
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
   109
            if ( r != 0 ) {
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
   110
                pr(i,"r != 0",r);
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
   111
                throw new RuntimeException();
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
   112
            }
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
   113
            break;
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
   114
        default:
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
   115
            if (WideStrictInline(strictValue(i)-0.5f) - strictValue(i) != 0) {
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
   116
                pr(i,"WideStrictInline(2^24-0.5) != 2^24",
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
   117
                   WideStrictInline(strictValue(i)-0.5f));
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
   118
            }
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
   119
            r = WideStrictInline(strictValue(i)-0.5f);
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
   120
            if ( r - strictValue(i) != 0 ) {
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
   121
                pr(i,"r != 2^24",r);
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
   122
                throw new RuntimeException();
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
   123
            }
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
   124
        }
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
   125
    }
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
   126
364944ba4e2f 8195981: Move some tests to OpenJDK for jdk_lang test group
amlu
parents:
diff changeset
   127
}