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