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