hotspot/test/compiler/6778657/Test.java
author jlaskey
Tue, 23 Jul 2013 12:00:29 -0300
changeset 19089 51cfdcf21d35
parent 5547 f4b087cbb361
permissions -rw-r--r--
8021130: Comments need to be tokens Reviewed-by: lagergren, attila Contributed-by: james.laskey@oracle.com
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
/*
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    26
 * @test
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    27
 * @bug 6778657
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    28
 * @summary Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    29
 */
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
public class Test {
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    32
  public static void check_f2i(int expect) {
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    33
    float check = expect;
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    34
    check *= 2;
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    35
    int actual = (int) check;
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    36
    if (actual != expect)
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    37
      throw new RuntimeException("expecting " + expect + ", got " + actual);
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    38
  }
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    39
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    40
  public static void check_f2l(long expect) {
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    41
    float check = expect;
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    42
    check *= 2;
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    43
    long actual = (long) check;
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    44
    if (actual != expect)
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    45
      throw new RuntimeException("expecting " + expect + ", got " + actual);
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    46
  }
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    47
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    48
  public static void check_d2i(int expect) {
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    49
    double check = expect;
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    50
    check *= 2;
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    51
    int actual = (int) check;
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    52
    if (actual != expect)
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    53
      throw new RuntimeException("expecting " + expect + ", got " + actual);
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    54
  }
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    55
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    56
  public static void check_d2l(long expect) {
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    57
    double check = expect;
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    58
    check *= 2;
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    59
    long actual = (long) check;
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    60
    if (actual != expect)
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    61
      throw new RuntimeException("expecting " + expect + ", got " + actual);
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    62
  }
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    63
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    64
  public static void main(String[] args) {
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    65
    check_f2i(Integer.MAX_VALUE);
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    66
    check_f2i(Integer.MIN_VALUE);
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    67
    check_f2l(Long.MAX_VALUE);
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    68
    check_f2l(Long.MIN_VALUE);
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    69
    check_d2i(Integer.MAX_VALUE);
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    70
    check_d2i(Integer.MIN_VALUE);
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    71
    check_d2l(Long.MAX_VALUE);
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    72
    check_d2l(Long.MIN_VALUE);
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    73
  }
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    74
}
f61e87294c59 6778657: Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
kvn
parents:
diff changeset
    75