1 /* 2 * Copyright (c) 2002, 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 * 27 * @summary converted from VM Testbase runtime/jbe/constprop/constprop02. 28 * VM Testbase keywords: [quick, runtime] 29 * 30 * @library /vmTestbase 31 * /test/lib 32 * @run driver jdk.test.lib.FileInstaller . . 33 * @run main/othervm vm.compiler.jbe.constprop.constprop02.constprop02 34 */ 35 36 package vm.compiler.jbe.constprop.constprop02; 37 38 // constprop02.java 39 40 /* Tests constant propagation by substitute integer, long, and double 41 by constant values. 42 */ 43 44 public class constprop02 { 45 public static void main(String args[]) { 46 boolean bPass = true; 47 constprop02 cpr = new constprop02(); 48 49 bPass &= cpr.verify(cpr.testDiv_un_opt()); 50 bPass &= cpr.verify(cpr.testDiv_hand_opt()); 51 System.out.println("------------------------"); 52 if (!bPass) { 53 throw new Error("Test constprop02 Failed."); 54 } 55 System.out.println("Test constprop02 Passed."); 56 } 57 58 String testDiv_un_opt() { 59 int ia, ib; 60 long lc, ld; 61 double de, df; 62 63 System.out.println("testDiv_un_opt:"); 64 ia = ib = 513; if ( 1 != ia / ib) return "case 1 failed"; 65 ia = -ia; if (-1 != ia / ib) return "case 2 failed"; 66 ia = ib = 1073741824; if ( 1 != ia / ib) return "case 3 failed"; 67 ia = -ia; if (-1 != ia / ib) return "case 4 failed"; 68 lc = ld = 8L; if ( 1 != lc / ld) return "case 5 failed"; 69 lc = -lc; if (-1 != lc / ld) return "case 6 failed"; 70 lc = ld = 1073741824L; if ( 1 != lc / ld) return "case 7 failed"; 71 lc = -lc; if (-1 != lc / ld) return "case 8 failed"; 72 ib = 0; 73 try { 74 ia = ia / ib; 75 return "case 9 failed"; 76 } catch (java.lang.Exception x) {/* good */} 77 ld = 0; 78 try { 79 lc = lc / ld; 80 return "case 10 failed"; 81 } catch (java.lang.Exception x) {/* good */} 82 try { 83 lc = lc % ld; 84 return "case 11 failed"; 85 } catch (java.lang.Exception x) {/* good */} 86 de = df = 16385.0; 87 if (1.0 != de / df) return "case 12 failed"; 88 de = -de; 89 if (-1.0 != de / df) return "case 13 failed"; 90 df = 0.0; 91 try { 92 de = de / df; 93 } catch (java.lang.Exception x) { 94 return "case 14 failed"; 95 } 96 try { 97 de = de % df; 98 de = 5.66666666666 % df; 99 } catch (java.lang.Exception x) { 100 return "case 15 failed"; 101 } 102 return null; 103 } 104 105 String testDiv_hand_opt() { 106 int ia, ib; 107 long lc, ld; 108 double de, df; 109 110 System.out.println("testDiv_hand_opt:"); 111 if ( 1 != 513 / 513) return "case 1 failed"; 112 if (-1 != -513 / 513) return "case 2 failed"; 113 if ( 1 != 1073741824 / 1073741824) return "case 3 failed"; 114 if (-1 != 1073741824 / -1073741824) return "case 4 failed"; 115 if ( 1 != 8L / 8L) return "case 5 failed"; 116 if (-1 != -8L / 8L) return "case 6 failed"; 117 if ( 1 != 1073741824L / 1073741824L) return "case 7 failed"; 118 if (-1 != 1073741824L / -1073741824L) return "case 8 failed"; 119 ib = 0; 120 try { 121 ia = -1073741824 / ib; 122 return "case 9 failed"; 123 } catch (java.lang.Exception x) {/* good */} 124 ld = 0L; 125 try { 126 lc = -1073741824L / ld; 127 return "case 10 failed"; 128 } catch (java.lang.Exception x) {/* good */} 129 try { 130 lc = -1073741824L % ld; 131 return "case 11 failed"; 132 } catch (java.lang.Exception x) {/* good */} 133 if (1.0 != 16385.0 / 16385.0) return "case 12 failed"; 134 if (-1.0 != -16385.0 / 16385.0) return "case 13 failed"; 135 df = 0.0; 136 try { 137 de = -1073741824L / df; 138 } catch (java.lang.Exception x) { 139 return "case 14 failed"; 140 } 141 try { 142 de = -1073741824L % 0.0; 143 de = 5.66666666666 % df; 144 } catch (java.lang.Exception x) { 145 return "cnase 15 failed"; 146 } 147 return null; 148 } 149 150 boolean verify(String str) { 151 boolean st = true; 152 153 if (null == str || str.equals("")) 154 System.out.println("OK"); 155 else { 156 st = false; 157 System.out.println("** "+str+" **"); 158 } 159 return st; 160 } 161 }