1 /* 2 * Copyright (c) 2002, 2020, 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/dead/dead16. 28 * VM Testbase keywords: [quick, runtime] 29 * 30 * @library /vmTestbase 31 * /test/lib 32 * @run main/othervm vm.compiler.jbe.dead.dead16.dead16 33 */ 34 35 package vm.compiler.jbe.dead.dead16; 36 37 // dead16.java 38 39 /* -- Test the elimination of redundant code. 40 Example: 41 42 double x; 43 x = x + 0; 44 x = x + 1; 45 x = x - 1; 46 return x; 47 */ 48 class doit { pause1(double x)49 static final double pause1(double x) { 50 for(int k = 1; k <= 10000; k++) { 51 x = x + 1.0; 52 } 53 return x; 54 } 55 pause2(double x)56 static final double pause2(double x) { 57 for(int k = 1; k <= 10000; k++) { 58 x = x - 1.0; 59 } 60 return x; 61 } 62 } 63 64 public class dead16 { 65 static double c = 1; 66 static double z = 0; main(String args[])67 public static void main(String args[]) { 68 69 System.out.println("un_optimized()="+un_optimized()+"; hand_optimized()="+hand_optimized()); 70 if (un_optimized() == hand_optimized()) { 71 System.out.println("Test dead16 Passed."); 72 } else { 73 throw new Error("Test dead16 Failed: un_optimized()=" + un_optimized() + " != hand_optimized()=" + hand_optimized()); 74 } 75 } 76 un_optimized()77 static double un_optimized() { 78 double x = 1; 79 // example 1 80 x = x + 0; 81 x = x - 0; 82 x = x * 1; 83 x = x / 1; 84 85 // example 2 86 x = x + c; 87 x = x - c; 88 x = x * c; 89 x = x / c; 90 91 // example 3 92 x = x + z; 93 x = x - z; 94 x = x * (z + c); 95 96 // example 4 97 x = doit.pause1(x); 98 x = doit.pause2(x); 99 x = doit.pause2(x); 100 x = doit.pause1(x); 101 x = doit.pause1(x); 102 x = doit.pause1(x); 103 x = doit.pause2(x); 104 x = doit.pause1(x); 105 x = doit.pause2(x); 106 x = doit.pause2(x); 107 x = doit.pause2(x); 108 x = doit.pause1(x); 109 110 return x; 111 } 112 113 // Code fragment after redundent code elimination hand_optimized()114 static double hand_optimized() { 115 int k; 116 double x = 1; 117 // example 1 118 119 // example 2 120 121 // example 3 122 123 // example 4 124 k = 10001; 125 126 return x; 127 } 128 } 129