Path: blob/master/test/hotspot/jtreg/compiler/runtime/Test6778657.java
41149 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*/2223/*24* @test25* @bug 677865726* @summary Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour27*28* @run main compiler.runtime.Test677865729*/3031package compiler.runtime;3233public class Test6778657 {34public static void check_f2i(int expect) {35float check = expect;36check *= 2;37int actual = (int) check;38if (actual != expect) {39throw new RuntimeException("expecting " + expect + ", got " + actual);40}41}4243public static void check_f2l(long expect) {44float check = expect;45check *= 2;46long actual = (long) check;47if (actual != expect) {48throw new RuntimeException("expecting " + expect + ", got " + actual);49}50}5152public static void check_d2i(int expect) {53double check = expect;54check *= 2;55int actual = (int) check;56if (actual != expect) {57throw new RuntimeException("expecting " + expect + ", got " + actual);58}59}6061public static void check_d2l(long expect) {62double check = expect;63check *= 2;64long actual = (long) check;65if (actual != expect) {66throw new RuntimeException("expecting " + expect + ", got " + actual);67}68}6970public static void main(String[] args) {71check_f2i(Integer.MAX_VALUE);72check_f2i(Integer.MIN_VALUE);73check_f2l(Long.MAX_VALUE);74check_f2l(Long.MIN_VALUE);75check_d2i(Integer.MAX_VALUE);76check_d2i(Integer.MIN_VALUE);77check_d2l(Long.MAX_VALUE);78check_d2l(Long.MIN_VALUE);79}80}81828384