Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/compiler/6778657/Test.java
32285 views
/*1* Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324/*25* @test26* @bug 677865727* @summary Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour28*/2930public class Test {31public static void check_f2i(int expect) {32float check = expect;33check *= 2;34int actual = (int) check;35if (actual != expect)36throw new RuntimeException("expecting " + expect + ", got " + actual);37}3839public static void check_f2l(long expect) {40float check = expect;41check *= 2;42long actual = (long) check;43if (actual != expect)44throw new RuntimeException("expecting " + expect + ", got " + actual);45}4647public static void check_d2i(int expect) {48double check = expect;49check *= 2;50int actual = (int) check;51if (actual != expect)52throw new RuntimeException("expecting " + expect + ", got " + actual);53}5455public static void check_d2l(long expect) {56double check = expect;57check *= 2;58long actual = (long) check;59if (actual != expect)60throw new RuntimeException("expecting " + expect + ", got " + actual);61}6263public static void main(String[] args) {64check_f2i(Integer.MAX_VALUE);65check_f2i(Integer.MIN_VALUE);66check_f2l(Long.MAX_VALUE);67check_f2l(Long.MIN_VALUE);68check_d2i(Integer.MAX_VALUE);69check_d2i(Integer.MIN_VALUE);70check_d2l(Long.MAX_VALUE);71check_d2l(Long.MIN_VALUE);72}73}74757677