1 /* 2 * Copyright (c) 2018, 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 * @test 26 * @bug 4169183 27 * @summary Check for correct inlining by the interpreter (widefp and strictfp). 28 * The default is widefp. A strictfp method was getting inlined 29 * into a widefp method. 30 */ 31 32 import java.io.PrintStream; 33 34 public class WideStrictInline { 35 static PrintStream out; 36 static float halfUlp; 37 38 static { 39 halfUlp = 1; 40 for ( int i = 127 - 24; i > 0; i-- ) 41 halfUlp *= 2; 42 } 43 44 public static void main(String argv[]) throws Exception { 45 out = System.err; 46 pr(-1,"halfUlp",halfUlp); 47 WideStrictInline obj = new WideStrictInline(); 48 for( int i=0; i<48; i++ ) 49 obj.instanceMethod( i ); 50 } 51 52 private static void pr(int i, String desc, float r) { 53 out.print(" i=("+i+") "+desc+" ; == "+r); 54 out.println(" , 0x"+Integer.toHexString(Float.floatToIntBits(r))); 55 } 56 57 private static strictfp float WideStrictInline(float par) { 58 return par; 59 } 60 61 public static strictfp float strictValue(int i) { 62 float r; 63 switch (i%4) { 64 case 0: r = -Float.MAX_VALUE; break; 65 case 1: r = Float.MAX_VALUE; break; 66 case 2: r = Float.MIN_VALUE; break; 67 default : r = 1L << 24; 68 } 69 return r; 70 } 71 72 void instanceMethod (int i) throws Exception { 73 float r; 74 switch (i%4) { 75 case 0: 76 if (!Float.isInfinite( WideStrictInline(strictValue(i)*2) + 77 Float.MAX_VALUE )) 78 { 79 pr(i, 80 "WideStrictInline(-Float.MAX_VALUE * 2) " + 81 "!= Float.NEGATIVE_INFINITY" 82 ,WideStrictInline(strictValue(i)*2) + Float.MAX_VALUE); 83 } 84 r = WideStrictInline(strictValue(i)*2) + Float.MAX_VALUE; 85 if ( !Float.isInfinite( r ) ) { 86 pr(i,"r != Float.NEGATIVE_INFINITY",r); 87 throw new RuntimeException(); 88 } 89 break; 90 case 1: 91 if (!Float.isInfinite(WideStrictInline(strictValue(i)+halfUlp) - 92 Float.MAX_VALUE )) { 93 pr(i,"WideStrictInline(Float.MAX_VALUE+halfUlp) " + 94 "!= Float.POSITIVE_INFINITY" 95 ,WideStrictInline(strictValue(i)+halfUlp) - Float.MAX_VALUE); 96 } 97 r = WideStrictInline(strictValue(i)+halfUlp) - Float.MAX_VALUE; 98 if ( !Float.isInfinite( r ) ) { 99 pr(i,"r != Float.POSITIVE_INFINITY",r); 100 throw new RuntimeException(); 101 } 102 break; 103 case 2: 104 if (WideStrictInline(strictValue(i)/2) != 0) { 105 pr(i,"WideStrictInline(Float.MIN_VALUE/2) != 0", 106 WideStrictInline(strictValue(i)/2)); 107 } 108 r = WideStrictInline(strictValue(i)/2); 109 if ( r != 0 ) { 110 pr(i,"r != 0",r); 111 throw new RuntimeException(); 112 } 113 break; 114 default: 115 if (WideStrictInline(strictValue(i)-0.5f) - strictValue(i) != 0) { 116 pr(i,"WideStrictInline(2^24-0.5) != 2^24", 117 WideStrictInline(strictValue(i)-0.5f)); 118 } 119 r = WideStrictInline(strictValue(i)-0.5f); 120 if ( r - strictValue(i) != 0 ) { 121 pr(i,"r != 2^24",r); 122 throw new RuntimeException(); 123 } 124 } 125 } 126 127 }