test/hotspot/jtreg/compiler/runtime/Test6778657.java
author iignatyev
Mon, 18 Feb 2019 09:31:07 -0800
changeset 53791 bec6c8739833
parent 47216 71c04702a3d5
permissions -rw-r--r--
8219157: vm/mlvm/mixed/stress/java/findDeadlock should be problem-listed only on mac Reviewed-by: thartmann
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1884
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
     1
/*
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2105
diff changeset
     2
 * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
1884
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
     4
 *
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
     8
 *
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    13
 * accompanied this code).
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    14
 *
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2105
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2105
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2105
diff changeset
    21
 * questions.
1884
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    22
 */
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    23
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    24
/*
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    25
 * @test
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    26
 * @bug 6778657
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    27
 * @summary Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    28
 *
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    29
 * @run main compiler.runtime.Test6778657
1884
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    30
 */
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    31
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    32
package compiler.runtime;
1884
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    33
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    34
public class Test6778657 {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    35
    public static void check_f2i(int expect) {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    36
        float check = expect;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    37
        check *= 2;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    38
        int actual = (int) check;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    39
        if (actual != expect) {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    40
            throw new RuntimeException("expecting " + expect + ", got " + actual);
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    41
        }
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    42
    }
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    43
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    44
    public static void check_f2l(long expect) {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    45
        float check = expect;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    46
        check *= 2;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    47
        long actual = (long) check;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    48
        if (actual != expect) {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    49
            throw new RuntimeException("expecting " + expect + ", got " + actual);
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    50
        }
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    51
    }
1884
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    52
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    53
    public static void check_d2i(int expect) {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    54
        double check = expect;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    55
        check *= 2;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    56
        int actual = (int) check;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    57
        if (actual != expect) {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    58
            throw new RuntimeException("expecting " + expect + ", got " + actual);
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    59
        }
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    60
    }
1884
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    61
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    62
    public static void check_d2l(long expect) {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    63
        double check = expect;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    64
        check *= 2;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    65
        long actual = (long) check;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    66
        if (actual != expect) {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    67
            throw new RuntimeException("expecting " + expect + ", got " + actual);
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    68
        }
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    69
    }
1884
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    70
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    71
    public static void main(String[] args) {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    72
        check_f2i(Integer.MAX_VALUE);
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    73
        check_f2i(Integer.MIN_VALUE);
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    74
        check_f2l(Long.MAX_VALUE);
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    75
        check_f2l(Long.MIN_VALUE);
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    76
        check_d2i(Integer.MAX_VALUE);
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    77
        check_d2i(Integer.MIN_VALUE);
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    78
        check_d2l(Long.MAX_VALUE);
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    79
        check_d2l(Long.MIN_VALUE);
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    80
    }
1884
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    81
}
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    82